Quartz CronTrigger expression between two dates
Is there a way to write a开发者_Go百科 Quartz CronTrigger expression that runs every day between two dates, for example starts at 11am 5th of Sep 2011 and ends at 11am 10th of June 2012?
Use an expression that means every day at 11:00am e.g. "0 0 11 * * ?".
Then set the startTime of the trigger to 5th of Sep 2011 10:59 am, and set the endTime of the trigger to 10th of June 2012 11:01 am.
Another solution I found is to specify a route policy (SimpleScheduledRoutePolicy) for the scheduled route and set the RouteStartDate and setRouteStopDate for this policy object.
A single cron expression doesn't facilitate running different schedules for the same period type, no matter which period is concerned, your differing schedule being the year period.
However other than your year difference all other periods have the same schedule. So... using these cron expressions:
cron1 = "0 0 23 5/1 SEP-DEC ? 2012"
cron2 = "0 0 23 1/1 JAN-JUN ? 2013"
you can switch the scheduler from using cron1 to cron2 sometime after 11:00.00 PM on 12/31/2012 but before 10:59.99 PM on 1/1/2013, though I wouldn't cut it so close as shown here. If you scheduler is reading its cron expression from the database or a configuration somewhere then just have it read in a new schedule every day at 11:30 PM. If you are storing your cron expressions in a database you could schedule to have a scheduler swap out the cron expression for your particular task using this chron3 below:
cron3 = "0 0 0 1 JAN ? 2013"
Silly me :o) today's date is Mar 13, 2013 so I'm sure this answer is a bit late for you!
精彩评论