• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quartz Scheduler that runs every x months

 
joei salijado
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using the Quartz (Java) library itself to do your task?
 
joei salijado
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.. Can you elaborate further on how this can be done in JobDetail?
Thanks.
 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic