Spring batch Cron expression: to run every 3 hours

user1705935 picture user1705935 · Sep 28, 2012 · Viewed 54.4k times · Source

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?

Answer

Christoph Leiter picture Christoph Leiter · Sep 28, 2012

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?