Reputation: 2113
I've created this method in SpringBoot
@Scheduled(cron = "0 16 * * * *")
public void sendMsg() {
}
to be executed At 16:00 pm (noon) every day:
but instead is executed several times per day
Upvotes: 0
Views: 169
Reputation: 3039
As was pointed by previous answers your expression is not valid "Spring expression", but rather unix expression. Spring utilizes Quartz-type which adds a value of seconds as a very first parameter:
+-------------------- second (0 - 59)
| +----------------- minute (0 - 59)
| | +-------------- hour (0 - 23)
| | | +----------- day of month (1 - 31)
| | | | +-------- month (1 - 12)
| | | | | +----- day of week (0 - 6) (Sunday=0 or 7)
| | | | | | +-- year [optional]
| | | | | | |
* * * * * * * command to be executed
Upvotes: 2
Reputation: 313
It should look like this:
@Scheduled(cron = "0 0 16 * * *")
public void sendMsg() {
}
Upvotes: 2
Reputation: 848
I think your expression should be 0 0 16 ? * * *
There are many online cron evaluator you can use for both evaluating an expression or creating one.
Upvotes: 2