karthik
karthik

Reputation: 295

spring cron for running every hour at 35th minute

I have a job that is scheduled to run every hour and I am using spring cron (0 0/35 * * * ). I am expecting the job to run at the 35th minute every hour but I noticed that the job gets triggered at the 35th minute and also at top of the hour. I am not sure why, any suggestions?

Thanks, Karthik

Upvotes: 0

Views: 5856

Answers (4)

daBigBug
daBigBug

Reputation: 353

Yes. Cron starts minutes at beginning of each hour (as we mention * for hour field). An alternative way of achieving your goal (executing a task at every 35th minute)can be as follows -

Make your cron trigger for every 5 minutes and increment a counter everytime the cron is triggered. Once the counter reaches 7 (i.e. 35 mins in your case), execute your goal and set the counter back to 0.

And if you want your goal to be executed at 35th minute of each hour, you should try

35 * * * *

Hope this helps!

Upvotes: 0

Quietust
Quietust

Reputation: 257

According to the Spring CronSequenceGenerator docs, the /35 in 0 0/35 * * * effectively means "every minute that's a multiple of 35", which includes 0 - if you only want it to trigger at 35 minutes after each hour, just use 0 35 * * * * (which includes all 6 parameters it wants).

Upvotes: 4

Freiheit
Freiheit

Reputation: 8757

I think your fields are out of order. The Spring Cron documenation seems to say that Spring uses standard cron expressions. https://crontab.guru is a good tool for checking cron expressions.

https://crontab.guru/#0_0/35___* shows

“At minute 0 past every 35th hour from 0 through 23.”

Whereas https://crontab.guru/#35____ shows

“At minute 35.”

I think you need to use 35 * * * *

Upvotes: 0

Vasu
Vasu

Reputation: 22412

Your cron expression is incorrect, so change it to 0 */35 * * * which runs only for every 35 minutes

Upvotes: 0

Related Questions