aspose file tools*
The moose likes Spring and the fly likes Cron expression with Spring Task scheduler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Cron expression with Spring Task scheduler" Watch "Cron expression with Spring Task scheduler" New topic
Author

Cron expression with Spring Task scheduler

Nitesh Patel
Ranch Hand

Joined: Mar 16, 2008
Posts: 33
Hi All,
I am using spring task scheduler to execute couple of task at particular time (like every day at 3:00 AM, every Monday at 10:00PM etc). For one of task I have specific requirement to execute it first Monday of every month at 3:00 AM. I search some forums and tried below expression but none of them work,

or

Above expression throws as below,


I have read the documentation of Spring but it does not mention about MON#1 format but some forums does.

I have also review the Spring source (for CronSequenceGenerator) but could not find any code to handle this expression (which interpret as First Monday of every month).

Can somebody please guide me ?

Thanks & Regards,
Nitesh
Manish Sridharan
Ranch Hand

Joined: Jul 19, 2005
Posts: 64
Hi Nitesh,

Can you try with this string "0 0 3 0 * 2" . This just might work. Also you can refer to this URL for setting up a cron expression.

Thanks,

Manish S.
Nitesh Patel
Ranch Hand

Joined: Mar 16, 2008
Posts: 33
Hi Manish,
Thanks for the reply. I figure it out using "0 1 0 1-7 * MON" expression (which ensure it only run for 1st 7 days of month - first week of month). But definitely I will try your expression as well.

Thanks,
Nitesh
Manish Sridharan
Ranch Hand

Joined: Jul 19, 2005
Posts: 64
Apologies the String should be It will make it run only once in a month. This works in cron job, not sure it works in spring task or not. you need to test it to confirm it.


Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cron expression with Spring Task scheduler