0
0
Spring Bootframework~20 mins

Cron expressions for scheduling in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cron Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
Identify the correct cron expression syntax for scheduling a task every 5 minutes
Which of the following cron expressions correctly schedules a Spring Boot task to run every 5 minutes?
A0 */5 * * * *
B0 0/5 * * * ?
C*/5 * * * *
D0 5 * * * ?
Attempts:
2 left
💡 Hint
Spring Boot cron expressions use six fields: second, minute, hour, day of month, month, day of week.
component_behavior
intermediate
2:00remaining
What is the output behavior of this scheduled method with given cron?
Given the Spring Boot scheduled method below, how often will it run? @Scheduled(cron = "0 15 10 * * ?") public void runTask() { System.out.println("Task executed"); }
Spring Boot
@Scheduled(cron = "0 15 10 * * ?")
public void runTask() { System.out.println("Task executed"); }
ARuns every minute during 10 AM hour
BRuns every hour at 15 minutes past
CRuns every day at 10:15 AM
DRuns every day at 15:10 (3:10 PM)
Attempts:
2 left
💡 Hint
Look at the hour and minute fields in the cron expression.
🔧 Debug
advanced
2:00remaining
Why does this cron expression cause a runtime error in Spring Boot?
Consider this cron expression used in @Scheduled: @Scheduled(cron = "0 0 25 * * ?") public void task() { /*...*/ } Why will this cause an error when the application runs?
Spring Boot
@Scheduled(cron = "0 0 25 * * ?")
public void task() { /*...*/ }
AHour field '25' is invalid because valid hours are 0-23
BMinute field '0' is invalid because it must be between 1-59
CDay of month '*' is invalid because it must be a number
DSecond field '0' is invalid because it must be between 1-59
Attempts:
2 left
💡 Hint
Check the allowed ranges for each cron field in Spring Boot.
state_output
advanced
2:00remaining
What is the output of this scheduled task with a complex cron expression?
Given this Spring Boot scheduled method: @Scheduled(cron = "0 0 9-17/2 * * MON-FRI") public void workHoursTask() { System.out.println("Working..."); } How often and when will this method print "Working..."?
Spring Boot
@Scheduled(cron = "0 0 9-17/2 * * MON-FRI")
public void workHoursTask() { System.out.println("Working..."); }
ARuns every 2 hours starting at 9 AM until 5 PM, Monday to Friday
BRuns every hour from 9 AM to 5 PM every day
CRuns once daily at 9 AM on weekdays
DRuns every 2 hours all days including weekends
Attempts:
2 left
💡 Hint
Look at the hour field with range and step, and the day of week field.
🧠 Conceptual
expert
3:00remaining
Which cron expression schedules a task to run at 8:30 AM on the last Friday of every month?
Select the correct Spring Boot cron expression that runs a task at 8:30 AM on the last Friday of each month.
A0 30 8 ? * 6L
B0 30 8 * * 5L
C0 30 8 ? * 6#5
D0 30 8 ? * 5L
Attempts:
2 left
💡 Hint
In cron, day of week 5 is Friday, and 'L' means last occurrence in the month.