问题
We are using quartz for scheduling the batch jobs. We are trying to apply weekend or holiday strategy for the job triggers. Looking at the quartz implementation, it was easy to implement weekend strategy using calendar(s), however for holiday implementation. If holiday(s) are defined well in advance before the job creation, it would be easy to handle along with weekend(s) in custom calendars. But, if holidays can be created dynamically, and the strategy to be applied at runtime, I thought it would be better if we handle this in CronTrigger, by overriding getNextTimeAfter method. But that isnot working, any thought, please help!
回答1:
If we've to make this work at a framework level, the best strategy is to override CronExpression class However, if we have to just use the framework and handle the holidays & weekend strategies, we followed the below approach. Whether it is a recurring job (OR) not, we create a simple job. At the end of current job execution, we reschedule the job based for next trigger time (after applying holiday / weekend strategy). This solved our issue.
回答2:
I had the same problem and I solve it using:
HolidayCalendar cal = new HolidayCalendar();
cal.addExcludedDate( someDate );
cal.addExcludedDate( someOtherDate );
sched.addCalendar("myHolidays", cal, false);
Trigger t = newTrigger().
...
.modifiedByCalendar("myHolidays") // but not on holidays
.build();
http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-04.html
来源:https://stackoverflow.com/questions/33999413/setting-weekend-or-holiday-strategy-while-scheduling-quartz-scheduler