简体   繁体   English

Quartz Scheduler,不包含特定时间范围

[英]Quartz scheduler with excluding specific time range

I want to schedule through Quartz scheduler excluding specific time ranges. 我想通过Quartz调度程序进行调度,但不包括特定的时间范围。

Ex : 2am - 3am and 5:30pm - 5:45pm 例如:2am-3am和5:30 pm-5:45 pm

Is there any other way to achieve this without the use cron expression and cron scheduler? 如果不使用cron表达式和cron调度程序,还有其他方法可以实现此目标吗?

This is what Quartz Calendars are used for. 这就是石英日历的用途。 Since in your case you want to exclude specific daytime ranges, you will want to use the DailyCalendar . 由于您要排除特定的白天范围,因此需要使用DailyCalendar

A single DailyCalendar can exclude a single day time range. 单个DailyCalendar可以排除一天的时间范围。 Since you want to exclude multiple (two) ranges, you will need to combine two DailyCalendars like so: 由于要排除多个(两个)范围,因此需要将两个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");

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM