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?
You can set the cron for every three hours as: 0 */3 * * * your command here ..
If you really need it to wait 5 minutes after service has started, you should consider using @Scheduled(fixedRate = 5000, initialDelay = 5000) .
Show activity on this post. ->cron('0 */12 * * *'); This cron will run the scheduler at every 12 hours.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With