aspose file tools*
The moose likes General Computing and the fly likes Cron Expression for Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Cron Expression for "After Every 30 days at midnight"  ?" Watch "Cron Expression for "After Every 30 days at midnight"  ?" New topic
Author

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

Karn Kumar
Ranch Hand

Joined: Aug 06, 2009
Posts: 143

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
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Karn Kumar
Ranch Hand

Joined: Aug 06, 2009
Posts: 143

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
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

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

Joined: Aug 06, 2009
Posts: 143

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
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Not a specifically Java-related question: moving.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cron Expression for "After Every 30 days at midnight" ?
 
Similar Threads
Java Calendar - add
java.util.Calendar, setTime and DST
duplicate created in AUTO INCREMENT in mysql if its possible?
Unix OS on Windows Vista ?
mod_jk error with POST request