在安排石英调度程序时设置周末或假日策略 [英] Setting weekend or holiday strategy while scheduling quartz scheduler

查看:61
本文介绍了在安排石英调度程序时设置周末或假日策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用石英来调度批处理作业.我们正在尝试将周末或假期策略用于工作触发器.观察石英的实现,很容易使用日历来实现周末策略,但是对于假期实现而言.如果假期是在创造工作之前提前定义的,则很容易在自定义日历中与周末一起处理.但是,如果可以动态创建假期并在运行时应用策略,那么我认为最好在CronTrigger中通过重写getNextTimeAfter方法来处理.但这是行不通的,任何想法,请帮忙!

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!

推荐答案

我遇到了同样的问题,并使用以下方法解决了该问题:

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

这篇关于在安排石英调度程序时设置周末或假日策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆