How do you schedule jobs with @Scheduled in Spring? How do cron, fixedRate and fixedDelay differ?
Short answer
Turn on @EnableScheduling and put @Scheduled on a method. fixedRate counts from when the previous run started, fixedDelay from when it finished, cron follows the calendar.
3 points to say:
fixedRate: from the start;fixedDelay: from the end, so runs never overlap;cron: real calendar time.- Spring cron has 6 fields, with seconds first, versus 5 fields in Unix cron.
- Always set
zone, and use day names (MON-FRI) rather than numbers.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.