Spring Boot cron expressions require six fields. Option B uses the correct six-field format with '0' seconds and '0/5' minutes to run every 5 minutes.
Option B has only five fields, which is invalid in Spring Boot.
Option B runs every 5 minutes but includes seconds as '0', which is correct, and the minute field is '*/5' which is also valid; however, the standard format is '0 0/5 * * * ?'.
Option B runs at 5 minutes past every hour, not every 5 minutes.
@Scheduled(cron = "0 15 10 * * ?") public void runTask() { System.out.println("Task executed"); }
The cron expression '0 15 10 * * ?' means at second 0, minute 15, hour 10, every day, any month, any day of week.
This schedules the task to run once daily at 10:15 AM.
@Scheduled(cron = "0 0 25 * * ?") public void task() { /*...*/ }
The hour field in a cron expression must be between 0 and 23.
Here, '25' is outside this range, causing a runtime error.
Minute and second fields with '0' are valid, and day of month '*' means every day, which is valid.
@Scheduled(cron = "0 0 9-17/2 * * MON-FRI") public void workHoursTask() { System.out.println("Working..."); }
The cron expression '0 0 9-17/2 * * MON-FRI' means:
- At second 0, minute 0
- Hours from 9 to 17 stepping every 2 hours (9,11,13,15,17)
- Every day of month
- Every month
- Only Monday to Friday
So the task runs at 9 AM, 11 AM, 1 PM, 3 PM, and 5 PM on weekdays.
In Spring Boot cron expressions:
- Day of week '5' means Friday.
- 'L' after day of week means last occurrence of that weekday in the month.
- Question mark '?' is used in day of month when day of week is specified.
Option D '0 30 8 ? * 5L' means at 8:30 AM, on the last Friday of every month.
Option D uses '6L' which is Saturday, not Friday.
Option D uses '*' in day of month which conflicts with day of week '5L'.
Option D uses '6#5' which means the 5th Saturday, which may not exist every month.