0
我想通过排除特定时间范围的Quartz调度程序进行调度。排除特定时间范围的石英调度程序
例如:上午02时 - 凌晨3点和下午5:30 - 下午5:45
是否有任何其他的方式来实现这一目标而无需使用cron表达式和cron调度?
我想通过排除特定时间范围的Quartz调度程序进行调度。排除特定时间范围的石英调度程序
例如:上午02时 - 凌晨3点和下午5:30 - 下午5:45
是否有任何其他的方式来实现这一目标而无需使用cron表达式和cron调度?
这是石英日历的用途。因为在你的情况下,你想排除特定的白天范围,你会想要使用DailyCalendar。
一个DailyCalendar可以排除一天的时间范围。由于您想要排除多个(两个)范围,因此您需要合并两个DailyCalendars,例如:
// calendar that excludes the 2am-3am day time range
DailyCalendar dc1 = new DailyCalendar(2,0,0,0,3,0,0,0);
// calendar that excludes the 5:30pm-5:45pm day time range
DailyCalendar dc2 = new DailyCalendar(17,30,0,0,17,45,0,0);
// combine the two calendars so that both ranges are excluded by dc2
dc2.setBaseCalendar(dc1);
// register the calendar with the scheduler
scheduler.addCalendar("MyExcludedDayTimeRangesCalendar", dc2, true, true);
MutableTrigger trigger = ... create SimpleTrigger/CronTrigger/DailyTimeInterval/CalendarIntervalTrigger instance
// associate the created trigger with the registered calendar - the trigger will exclude calendar's time ranges
trigger.setCalendarName("MyExcludedDayTimeRangesCalendar");
...
为什么您不想使用cron调度程序? 另外,我不是100%清楚你想要做什么,你可以换个例子吗? – dquijada
@dquijada我对cron表达式不太好,想知道,石英调度程序api中是否还有其他库可以完成这项工作? 最后,cron表达式将被解析,并将解析值设置为对象的变量。 所以,假设应该有一些setter方法来做相同的! –