Meaningless Drivel is fun!*
The moose likes Other Open Source Projects and the fly likes Quartz Scheduler that runs every x months Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Quartz Scheduler that runs every x months" Watch "Quartz Scheduler that runs every x months" New topic
Author

Quartz Scheduler that runs every x months

joei salijado
Greenhorn

Joined: Sep 23, 2009
Posts: 11
Hi!

I have a cron trigger that is scheduled to run once every month. This works fine but when I change the schedule to run every x months, let's say, every 3 months, it will not be followed. Regardless of the start date, it will always run on March, June, Sept, and Dec of every year. Here's my cron expression:

     0 30 10 20 */3 ? *

I recently came across with the documentation of Quartz's cron expression and was enlightened by the explanation on the "/" character.
     The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7",
     it does NOT mean every 6th month, please note that subtlety.


Now I'm wondering if it's possible to schedule a cron trigger that runs every x months and what will be the correct cron expression for this.
Badly need your help guys.. Thanks!
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
How about using the Quartz (Java) library itself to do your task?
joei salijado
Greenhorn

Joined: Sep 23, 2009
Posts: 11
James Ward wrote:How about using the Quartz (Java) library itself to do your task?


Hi James,
I'm not quite sure what you mean but I'm using Quartz's CronTrigger class in defining the details of the schedule as such:
    

James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
Oh Ok...

I guess then you would have see the APIs (http://quartz.sourceforge.net/javadoc/index.html)

TriggerUtils class has many convenience methods (to avoid figuring out cron expressions!) like makeHourlyTrigger, makeMonthlyTrigger etc.

This is pseudo code, just to give you an idea:

You can put additional logic in your jobDetail class to do-whatever-you-want or not-do, to achieve for example doing-your-task only on even months etc.

I have used these APIs in the past to set triggers instead of CronTrigger class.

joei salijado
Greenhorn

Joined: Sep 23, 2009
Posts: 11
Ok thanks. My monthly cron trigger schedule (fires every month) is working fine so I'm still checking if I can continue using CronTrigger as my trigger and just change something in JobDetail like you said.
joei salijado
Greenhorn

Joined: Sep 23, 2009
Posts: 11
Hi.. Can you elaborate further on how this can be done in JobDetail?
Thanks.
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
joei salijado wrote:Hi.. Can you elaborate further on how this can be done in JobDetail?
Thanks.


Well some custom logic...

If you store when actual 'Job' ran succesfully last time; you can always refer that information to decide whether it should run 'this' time or not etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Quartz Scheduler that runs every x months