• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cron Expression for "After Every 30 days at midnight" ?

 
Ranch Hand
Posts: 153
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All ,

Can anybody suggest that how can i run job after every 30 days

I tried with the

0 0 0 1/30 * ? *

on the http://www.cronmaker.com/


but it shows some output like


1. Monday, October 31, 2011 12:00 AM
2. Tuesday, November 1, 2011 12:00 AM ---- (This is immediate day after 31)
3. Thursday, December 1, 2011 12:00 AM
4. Saturday, December 31, 2011 12:00 AM
5. Sunday, January 1, 2012 12:00 AM

Can anybody suggest way or any alternate way ...


Thanks in advance..

Regards,
Chetan
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never seen a slash in a crontab entry. I'm surprised that's not an error.

But...I don't think you can schedule a cron job to run every 30 days. You can pick a day of week or day of the month...but every 30 days requires something to remember the last time it ran. I don't think cron does that.
 
Karn Kumar
Ranch Hand
Posts: 153
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Slash Can be used and is mentioned in the class CronExpression

http://quartz-scheduler.org/api/1.8.5/org/quartz/CronExpression.html

But now the problem is if it runs on 31Dec then it will again run on 1 Jan which should not happen it should run 30 days after 31 Dec say 30 Jan .......
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't know there was such a class. If you read the api carefully, "1/30" means "run it on the 1st and 30 days after the first" - NOT 'run every 30 days'. I still don't see how to schedule it like you want. It doesn't work that way.
 
Karn Kumar
Ranch Hand
Posts: 153
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi fred ,

You are right that it will run on 1 st and 30 days after that , but i want to run it after 30 days interval....


Thanks...!!


 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know of a way to do it with cron. You may be able to do it by having a dummy file. When you run, you first check to see if the file is 30 days old or not. If not, shut down. If it is, run the job, then touch the file.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a specifically Java-related question: moving.
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic