Running Multiple Jobs using Scheduler in Real time application - java

Can anyone help me out to choose which scheduler between "Quartz" or "Quartz+Spring" to run multiple jobs simultaneously in real time application.

Quartz can run multiple jobs without Spring. Use Spring if you want the features that Spring brings to the table. I would use Spring, because Spring is a great integration framework and makes it easy to integrate technologies like Quartz into an application.

I prefer TimerTask class.
Refer this tutorial
http://www.mkyong.com/java/how-to-run-a-task-periodically-in-java/

Related

Best Way to Update Database Periodically in Java Web Application

I have a java web application which is running on Glassfish server. Using war file i use to deploy the application in various servers. Now to keep my application's database updated, i want to run some class (inside from application)periodically without any user interaction (should not depends on application is running or not/current users/session). i have seen that using some Timer and TimerTask class i can run any job periodically. But how to initialize it for the first time?
Please put your thoughts on how to complete this process.
Use a Job scheduler. Consider Quartz http://quartz-scheduler.org/ and start it when the program starts. The good part about using a scheduler is your program is more maintainable and you can easily create other new jobs
Create a servlet and make it load on startup. There you can initialize your task, I think.
Quartz is a good solution like already suggested. But if you need something more lite weight, I would have a look at the scheduled executor:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html
It is less flexible than Quartz, but you don't need to add any dependency and it might be that it is good enough for your needs.
About starting up; I normally use Spring to wire up my application and its dependencies. So starting schedulers and running scheduled tasks is then a no brainer.
The answer changes depending on the version of Java EE you are using. In Java EE 5 and previous versions you would use a ServletContextListener to run code (call an EJB) at deployment time that used the Timer API. In Java EE 6+ you can use the #Schedule annotation which uses annotations and a cron-type syntax to schedule your task at deployment time.
Of course if you don't need automatic deployment time scheduling then you'd just create some web form that calls a EJB when submitted which in turn calls the Timer API programmatically.
For more see the Java EE tutorial

job scheduling with java and spring 3

Hi I have one requirement to schedule task using java. I can use threads and timer task of java but if we restart application or server that threads will get stop and after starting application there is no schedule task. so please help me is there any way for that i am using java with spring 3.1
Spring batch is the solution for your case. you can find documentation here , documentation is pretty good with sample programs which are extensively used. It has the feature to restart the job.
You could try with quartz-scheduler, Its easy to use with spring.
For your reference : http://www.mkyong.com/tutorials/quartz-scheduler-tutorial/

Scheduling tasks in Java/Spring

There is a requirement in the project that will have a scheduled task that will do some job.
The project is Spring based and the scheduled job will be part of the application war.I have
never implemented this kind of functionality before.
I have heard of Quartz. Also, I read somewhere that Spring provides some functionality to schedule tasks. So, I was thinking if I am already using Spring then why to go for some other API(Quartz).
I am not sure which one to use? what will be the pros/cons of one over another?
Please suggest what will be the best way to approach my requirement.
I have used Spring's Task execution and scheduling - http://static.springsource.org/spring/docs/3.0.x/reference/scheduling.html

How to do background tasks in struts2?

i had a look on the struts plugins list here and wasn't able to find a plugin to do background/scheduled tasks.
What i want to do, is run a daily task that pulls files from a few servers. I'd like this task to be run from within the web app, so that my importer gets access to all the data classes, also it would be less complicated IMO.
Any common way to go about this?
Thanks
Your best bet is probably Quartz which provides a way to define jobs, and a number of triggers, including cron like expressions. It can be embedded in your app.
Together with Struts2 I use the Spring Plugin for this Issue.
With Spring you can easy define Timer Tasks or Quartz Jobs to execute
Background Jobs.

How to use Quartz with EJB3?

I want to be able to :
define different jobs and triggers.
modify the expirations dates and intervals on demand
pause or cancel an execution (trigger)
the jobs would be ejbs or call ejbs and i would want to manage everything from the website (the user will have to define the executions)
So i looked at the timerservice, timerobjects, timer and timerhandle. But i think it can't answer to all my needs
Quartz, on the other hand, allows me to do every thing that i want, but i haven't the slightest clue on how to integrate this into my jboss.
I read that quartz uses its own threadpool, and i don't know how to handle all this.
I use Jboss Seam in my project, but the seam/quartz integration is very limited (or the documentation is) and not 100% safe (seen on their forum : 'run forever' tasks end after only a few weeks)
If someone managed to integrate a good scheduler into his application server (jboss is a plus) and could give me directions, advices, or even code snippets, i would be thrilled.
Thanks in advance.
I have some experience integrating Quartz into a Weblogic (no jboss experience, sorry) application server. Quartz has a built in listener class that will be called upon server startup (per J2EE specs) that automatically configure the Quartz scheduler. Then in another startup class you can retrieve that scheduler, add jobs and begin serving those jobs.
You generally don't need to worry about the threadpool, Quartz can handle all this itself if you want it too. It gets its information from a properties files on startup that you can define or use the default one that comes with quartz. I have been using the default because it works for my purposes.
As far as defining jobs, you create your job classes and call your ejbs from there. It is rather very simple.
For your reading pleasure:
All Quartz documentation
Quartz JavaDoc
Cookbook containing lots of code snippets
Hope that's enough to get you started!
Great news! JBoss has a built-in scheduler already.
Since the EJB 2.0 specification included running stateless session beans and MDBs at scheduled intervals, all application servers have included this capability for some time now.
Here is an example of configuring JBoss to run a class using its built-in scheduler:
http://www.jboss.org/community/wiki/Scheduler
The best part about JBoss' implementation is that it is based on the MBean specification, which means that you can create/update/delete scheduled tasks at runtime.
Ok, i am sorry, i found in the sources of Jboss Seam just what i needed :
QuartzDispatcher to create QuartzTriggerHandle wich fires seam event at specified time and date and is manually pausable, resumable and stoppable. I use an #observer on the method i wanted to execute.
It's simple, and it works so far.
As pointed out by Poindexter, the Quartz documentation has nice starting points: Tutorial for Developing with Quartz, Examples of Usage, Cook Book (Quick How-Tos in the form of code examples), etc.
The What Is Quartz article is really good too (even if a bit old now).
For integration with JBoss, maybe have a look at How to configure a Quartz service on JBoss Wiki.

Categories

Resources