Setting weekend or holiday strategy while scheduling quartz scheduler

会有一股神秘感。 提交于 2020-01-06 21:20:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!