Is it allowed / working to have multiple @Scheduled annotations at one method?
@Scheduled(cron = "0 5 0 * * *", zone = "Europe/Stockholm")
@Scheduled(fixedRate = 1000 * 60 * 20, initialDelay = 1000 * 60 * 5)
public void setSalariesAsArchived() {
//...
}
Yes, this is perfectly legal as @Scheduled is a @Repeatable annotation like stated in the Javadoc for @Schedules
Container annotation that aggregates several
Scheduledannotations. Can be used natively, declaring several nestedScheduledannotations. Can also be used in conjunction with Java 8's support for repeatable annotations, whereScheduledcan simply be declared several times on the same method, implicitly generating this container annotation.
So you can either use it as you did, or use @Schedules to wrap it like in the following example
@Schedules({
@Scheduled(cron = "0 5 0 * * *", zone = "Europe/Stockholm"),
@Scheduled(fixedRate = 1000 * 60 * 20, initialDelay = 1000 * 60 * 5)
})
public void setSalariesAsArchived() {
//...
}
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