de guide
de guide

Reputation: 35

spring boot @scheduled triggered after the time expected

I try to trigger a task every day at 7h45 in spring boot by this way

@Scheduled(cron = "45 7 * * * ?")
public void method() {....}

And I saw this morning that it triggered at around 9h09. I checked that server time correspond to the time displayed on my computer. Furthermore the server is running on windows So Why this difference of time ?

Upvotes: 0

Views: 158

Answers (1)

Simon Martinelli
Simon Martinelli

Reputation: 36103

The first element in Spring cron expressions are seconds. So I assume that it was run at 9:07:45

This would be the correct expression:

0 45 7 * * ?

Check out: https://spring.io/blog/2020/11/10/new-in-spring-5-3-improved-cron-expressions

Upvotes: 1

Related Questions