Quartz Scheduler Example Programs and Sample Code : Quartz Code Snippets : How-To: Create a Trigger that Executes Every Week
How-To: Create a Trigger that Executes Every Week
If you want a trigger that always fires at a certain time of day each week, use CronTrigger or CalendarIntervalTrigger because they can preserve the firing time across daylight savings time changes.
Using CronTrigger
Create a CronTrigger. that executes every Wednesday at 3:00 PM:
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startNow()
.withSchedule(weeklyOnDayAndHourAndMinute(DateBuilder.WEDNESDAY, 15, 0))
     // fire every wednesday at 15:00
.build();
- OR -
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startNow()
.withSchedule(cronSchedule("0 0 15 ? * WED"))
     // fire every wednesday at 15:00
.build();
Using SimpleTrigger
Create a SimpleTrigger that executes at 3:00 PM tomorrow, and then every 7 * 24 hours after that.
Note:  
Be aware that this trigger might not always fire at 3:00 PM, because adding 7 * 24 hour on days when daylight savings time shifts can result in an execution time of 2:00 PM or 4:00 PM, depending upon whether the 3:00 PM time was started during DST or standard time.
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startAt(tomorrowAt(15, 0, 0) // first fire time 15:00:00 tomorrow
.withSchedule(simpleSchedule()
.withIntervalInHours(7 * 24)
              // interval is actually set at 7 * 24 hours worth of milliseconds
.repeatForever())
.build();
Using CalendarIntervalTrigger
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startAt(tomorrowAt(15, 0, 0) // 15:00:00 tomorrow
.withSchedule(calendarIntervalSchedule()
.withIntervalInWeeks(1)) // interval is set in calendar weeks
.build();
Copyright © 2010-2016 Software AG, Darmstadt, Germany.

Product Logo |   Feedback