I need to write a scheduler for our application however not sure which will suit better for our scenario.
Can somebody let me know the advantages of quartz scheduler(Cron type scheduling) over java Timer task API?
And which one is suitable for the following scenario:
I am reading the triggering time from the configuration file which contains two values:
1) Scheduling Time: time when the scheduler will trigger
2) Unit: It can be Minutes, hours and days
Case 1: if Unit is Minutes:
If suppose Scheduling time in configuration file is 5 and unit is minutes then the scheduler should be trigerred in every Five minutes from the current time.
Case 2: if unit is Hours
It can take value between 0-23, suppose Scheduling time is 22 and unit is hours then the scheduler should be trigerred every day at 10 PM.
Case 3: if unit is days
If scheduling time is 40 and unit is days then the scheduler should be trigerred after every 40 days. suppose if todays date is 27th may then schduler should be trigerred on 6th July.
I know it is a kind of complex requirement and want to decide on which is the best suitable for this (Quartz or Timertask) along with the quartz scheduler adavantages over timer tasks.
Well I know that Quartz allows you to set CRON expressions which would quite easily let you schedule tasks for the requirements you specified there.
E.g. a cron for 10pm every night would be
0 0 22 * ? *
which in CRON terms is very simple.
I love this place!
Joined: Jul 30, 2010
Hey thanks for the reply..
You mean It allows us to schedule the tasks quite easily like 3rd day of every month or last tuesday of month...is there any other advantages of using quartz scheduler over Timer task (or related to performance)?
For my scenario I have to make several complex calculations to evaluate the cron expression which can be done easily using the timer task...because I feel it does not have any parameter for the number of days..say if I want to schedule it after every 40 day from the current day then I have to make lot of calculations to set the cron expression, and will have to set each of the cron expression parameter to make sure it is triggered after exactly 40 days from now right?
Well think about it, if you have to run the job every 40 days and your app stops working after 29 days, how do you plan on working out that the job should be run in 11 days when you restart it? You should take things like that into consideration.
From the Quartz page:
Why not just use java.util.Timer?
Since JDK 1.3, Java has "built-in" timer capabilities, through the java.util.Timer and java.util.TimerTask classes - why would someone use Quartz rather than these standard features?
There are many reasons! Here are a few:
Timers have no persistence mechanism.
Timers have inflexible scheduling (only able to set start-time & repeat interval, nothing based on dates, time of day, etc.)
Timers don't utilize a thread-pool (one thread per timer)
Timers have no real management schemes - you'd have to write your own mechanism for being able to remember, organize and retrieve your tasks by name, etc.
...of course to some simple applications these features may not be important, in which case it may then be the right decision not to use Quartz.
At the end of the day it is down to your requirements.
Joined: Jul 30, 2010
Hey Thanks for such a nice explanation, this is wat I was looking for
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com