Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cron expression to run every two days from the current day

 
sivachithambaram Rangaraj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to write a cron expression to execute on every two days from the current day.

I have used one expression like "1 0 18 */2 * ?" but it is firing only in the odd days.. i guess becaz it is starting it from day 1 of the month.

So can anyone help on this?

Thanks
Siva
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sivachithambaram Rangaraj wrote:
I have used one expression like "1 0 18 */2 * ?" but it is firing only in the odd days.. i guess becaz it is starting it from day 1 of the month.

You mean the cron expression firing correctly after each 2 days, in your case, starting from 1, :
1 3 5 so on...
Thats what you want, right OR you want even/odd days execution ??
For latter case, try using "2/2" - "fire every 2 days starting on the second day of the month".

For more info:
http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html
 
sivachithambaram Rangaraj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks rohan ,for the reply..

My scenario is like if i schedule it on 10th of feb the job should be executed for every n days starting on 10th feb ..not on the even days alone or not on the odd days alone...the intereval may vary from 1 to n...

 
sivachithambaram Rangaraj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it by building a simple trigger with the specified interval multiplied by 24..

i.e Trigger t=Triggerutils.makeHourlyTrigger(interval*24);'
This will trigger for every n days ..


Thanks
Siva
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sivachithambaram Rangaraj wrote:Thanks rohan ,for the reply..

Please go though my signature.
sivachithambaram Rangaraj wrote:My scenario is like if i schedule it on 10th of feb the job should be executed for every n days starting on 10th feb ..not on the even days alone or not on the odd days alone...the intereval may vary from 1 to n...

Then I think, your expression should work.
I solved it by building a simple trigger with the specified interval multiplied by 24..

Are you sure, multiplying it by 24 hours solves your original requirement, i'e firing after each 2 days
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, any moderator watching this thread, please move it to "Other JSE/JEE API" section.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:Also, any moderator watching this thread, please move it to "Other JSE/JEE API" section.

Why? It sounds like it is about cron which is a UNIX tool.
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:
Sagar Rohankar wrote:Also, any moderator watching this thread, please move it to "Other JSE/JEE API" section.

Why? It sounds like it is about cron which is a UNIX tool.

This is what the OP wrote:
sivachithambaram Rangaraj wrote:
i.e Trigger t=Triggerutils.makeHourlyTrigger(interval*24);'

and TriggerUtils is the Quartz class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic