开发者

Quartz Scheduing: Using DailyCalendar

I am trying to schedule a quartz job according to the following plan:

Job runs daily and should only be executed between 9:30am and 6:00pm. I am trying to achieve this via DailyCalendar. Here what my DailyCalendar looks like:

DailyCalendar dCal = new DailyCalendar(startTimeString, endTimeString);
dCal.setTimeZone(TimeZone.getDefault());
dCal.setInvertTimeRange(true);

where start and end time strings are of the format HH:MM

Next, I try to schedule this job:

Scheduler myscheduler = StdSchedulerFactory.getDefaultScheduler();
SimpleTrigger trigger = new SimpleTrigger();
myscheduler.addCalendar("todcal", cal, true, true);
trigger.setName("TRIGGER " + alertName);
trigger.setJobName(alertName);
trigger.setJobGroup(alertName);
trigger.setCalendarName("todcal");
logger.info("Adding TOD job");
myscheduler.scheduleJob(trigger);    // line causing exception
myscheduler.start();

As soon as scheduleJob is called I see the following Exception:

Based on configured schedule, the given trigger will never fire.

The configu开发者_如何学Cration seems fine to me but I cant find any sample code for using DailyCalendar so I could be wrong here. Please help


You don't seem to be setting a repeat count or repeat interval on your trigger. So it will only fire once at the current moment (because you did not set a future start time), which probably happens to be during the calendar's exclusion time - which is why it would be calculated that it will never fire.


Job runs daily and should only be executed between 9:30am and 6:00pm.

How often should the job be executed within that timeframe? Once? Once an hour? Every 10 seconds?

You need to define the repeat interval for your trigger. Look at setRepeatInterval(long repeatInterval) method of SimpleTrigger. It defines in milliseconds the interval with which the trigger will repeat.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜