Dashboard > Quartz 1 > ... > Documentation > MonthlyTrigger
  Quartz 1 Log In View a printable version of the current page.  
  MonthlyTrigger
Added by Aaron Craven, last edited by Aaron Craven on Jul 17, 2005  (view change)
Labels: 
(None)

Trigger That Executes Every Month

(note all examples fire at 5:00 AM.)

Using org.quartz.helpers.TriggerUtils

(TriggerUtils note: in 1.5.x, org.quartz.helpers.TriggerUtils has moved to org.quartz.TriggerUtils.)

Trigger That Executes On the 15th of Every Month
Trigger trigger = TriggerUtils.makeMonthlyTrigger(15, 5, 0);
trigger.setName("trigger1");
trigger.setGroup("group1");

Doing it manually

Unlike the rest of the examples here, this one cannot be implemented with SimpleTrigger, because there is not an even interval of time between each month. Our only option is CronTrigger, but what we can do with CronTrigger is harldy limited:

CronTrigger That Executes On the First Day of Every Month
CronTrigger trigger = new CronTrigger("trigger1", "group1");
trigger.setCronExpression("0 0 5 1 * ?");
CronTrigger That Executes On the 15th of Every Month
CronTrigger trigger = new CronTrigger("trigger1", "group1");
trigger.setCronExpression("0 0 5 15 * ?");
CronTrigger That Executes On the Last Day of Every Month
CronTrigger trigger = new CronTrigger("trigger1", "group1");
trigger.setCronExpression("0 0 5 L * ?");
CronTrigger That Executes On the First Weekday of Every Month
CronTrigger trigger = new CronTrigger("trigger1", "group1");
trigger.setCronExpression("0 0 5 1W * ?");
CronTrigger That Executes On the Last Weekday of Every Month
CronTrigger trigger = new CronTrigger("trigger1", "group1");
trigger.setCronExpression("0 0 5 LW * ?");

There are other possible combinations as well, which are more fully covered in the API documentation. All of these options were made by simply changing the day-of-month field. Imagine what you can do if you leverage the other fields as well!

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators