Paris Tao
Paris Tao

Reputation: 365

spring scheduled task run every second with cron(0 0/10 * * * ? )

it's strange, i setup corn as

@Scheduled(cron= "0 0/10 *  * * ? ")

It did trigger every 10 minutes, but the issue is task runs each second.

Upvotes: 18

Views: 70815

Answers (2)

DMC19
DMC19

Reputation: 927

If you want to execute every 10 seconds, you should have this:

@Scheduled(cron= "0/10 * * ? * *")

before the / numbers 0 to 9 are possible, the mentioned schedule kicks of at the start of every 10 second interval within the minute. 5/10 kicks after 5 seconds within the 10 second interval.

Upvotes: 6

Roaslin
Roaslin

Reputation: 199

This is what javadoc says :

CronSequenceGenerator

the first field of the cron is for seconds.

Upvotes: 19

Related Questions