Quartz Scheduler Example Programs and Sample Code : Quartz Code Snippets : How-To: Create a Trigger that Executes Every Month
How-To: Create a Trigger that Executes Every Month
Using CronTrigger
Create a CronTrigger that executes on a specified day each month at 3:00 PM.
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startNow()
.withSchedule(monthlyOnDayAndHourAndMinute(5, 15, 0))
         // fire on the 5th day of every month at 15:00
.build();
- OR -
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startNow()
.withSchedule(cronSchedule("0 0 15 5 * ?"))
          // fire on the 5th day of every month at 15:00
.build();
- OR -
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startNow()
.withSchedule(cronSchedule("0 0 15 L * ?"))
           // fire on the last day of every month at 15:00
.build();
- OR -
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startNow()
.withSchedule(cronSchedule("0 0 15 LW * ?"))
          // fire on the last weekday day of every month at 15:00
.build();
- OR -
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startNow()
.withSchedule(cronSchedule("0 0 15 L-3 * ?"))
          // fire on the third to last day of every month at 15:00
.build();
The triggers shown above were created by changing the day-of-month field. There are other possible combinations as well, which are more fully covered in the API documentation.
Using CalendarIntervalTrigger
trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startAt(tomorrowAt(15, 0, 0) // 15:00:00 tomorrow
.withSchedule(calendarIntervalSchedule()
.withIntervalInMonths(1)) // interval is set in calendar months
.build();
Copyright © 2010-2016 Software AG, Darmstadt, Germany.

Product Logo |   Feedback