Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring batch Cron expression: to run every 3 hours

Tags:

I want my spring batch job to run every 3 hours

I used expression * * */3 * * ? this starts the job at the hour that is divisible by 3 e.g. say the server was started at 2 PM the job starts executing only at 3 PM - so far so good but the job keeps starting every second! Is it because I used * in the 1st position?

I tried 0 0 */3 * * ? but it is erroring out. What is the best way to achieve this?

like image 324
user1705935 Avatar asked Sep 28 '12 10:09

user1705935


People also ask

How do I run a Cron job every 3 hours?

You can set the cron for every three hours as: 0 */3 * * * your command here ..

How do I run a spring batch job every 5 minutes?

If you really need it to wait 5 minutes after service has started, you should consider using @Scheduled(fixedRate = 5000, initialDelay = 5000) .

How do I run a Cron job every 12 hours?

Show activity on this post. ->cron('0 */12 * * *'); This cron will run the scheduler at every 12 hours.


1 Answers

The format is

second, minute, hour, day, month, weekday

so the correct cron expression should be

0 0 */3 * * * 

If that doesn't work, what's the exact error message you are getting?

like image 87
Christoph Leiter Avatar answered Oct 21 '22 04:10

Christoph Leiter