Bird
Raised Fist0
Spring Bootframework~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does a cron expression in Spring Boot primarily specify?
easy
A. The output format of the task
B. When a scheduled task should run
C. The name of the scheduled task
D. The priority of the task

Solution

  1. Step 1: Understand the purpose of cron expressions

    Cron expressions define timing details for scheduling tasks.
  2. Step 2: Identify what cron expressions control in Spring Boot

    They tell Spring Boot exactly when to run a method automatically.
  3. Final Answer:

    When a scheduled task should run -> Option B
  4. Quick Check:

    Cron expression = schedule time [OK]
Hint: Cron expressions set task run times, not names or outputs [OK]
Common Mistakes:
  • Thinking cron sets task names
  • Confusing cron with output formatting
  • Assuming cron controls task priority
2. Which of the following is the correct syntax to schedule a method to run every minute using Spring Boot's @Scheduled annotation with a cron expression?
easy
A. @Scheduled(cron = "*/1 * * * *")
B. @Scheduled(cron = "* * * * *")
C. @Scheduled(cron = "0 0/1 * * ?")
D. @Scheduled(cron = "0 * * * * *")

Solution

  1. Step 1: Recall Spring Boot cron format

    Spring Boot cron uses 6 fields: seconds, minutes, hours, day, month, weekday.
  2. Step 2: Identify correct expression for every minute

    "0 * * * * *" means at 0 seconds every minute, every hour, every day.
  3. Final Answer:

    @Scheduled(cron = "0 * * * * *") -> Option D
  4. Quick Check:

    6-field cron with 0 seconds = every minute [OK]
Hint: Spring Boot cron needs 6 fields; seconds first [OK]
Common Mistakes:
  • Using 5-field cron (missing seconds)
  • Misplacing seconds field
  • Using '?' in wrong position
3. Given the cron expression "0 15 10 * * ?" in a Spring Boot @Scheduled annotation, when will the scheduled method run?
medium
A. Every day at 10:15 AM
B. Every hour at 15 minutes past
C. Every day at 10:00 AM
D. Every minute at 15 seconds past

Solution

  1. Step 1: Break down the cron fields

    Fields: seconds=0, minutes=15, hours=10, day=any, month=any, weekday=? (no specific day)
  2. Step 2: Interpret the timing

    Means run at 10:15:00 every day, ignoring weekday.
  3. Final Answer:

    Every day at 10:15 AM -> Option A
  4. Quick Check:

    0 15 10 * * ? = daily 10:15 AM [OK]
Hint: Seconds first, then minutes, then hours in Spring cron [OK]
Common Mistakes:
  • Confusing minutes and hours positions
  • Ignoring '?' meaning in weekday
  • Assuming it runs every hour
4. Identify the error in this Spring Boot cron expression: @Scheduled(cron = "0 0 25 * * ?")
medium
A. Seconds field missing
B. Day of month field is invalid
C. Hour value 25 is invalid
D. Weekday field cannot be '?'

Solution

  1. Step 1: Check each cron field's valid range

    Seconds: 0-59, Minutes: 0-59, Hours: 0-23, Day: 1-31, Month: 1-12, Weekday: 1-7 or ?
  2. Step 2: Identify invalid value

    Hour field is 25, which is outside 0-23 range, causing error.
  3. Final Answer:

    Hour value 25 is invalid -> Option C
  4. Quick Check:

    Hour must be 0-23, 25 is invalid [OK]
Hint: Hours max 23 in cron, check all field ranges [OK]
Common Mistakes:
  • Using hour > 23
  • Forgetting seconds field
  • Misusing '?' in day or weekday
5. You want to schedule a Spring Boot task to run every Monday at 8:30 AM, but only during the months of June, July, and August. Which cron expression correctly achieves this?
hard
A. "0 30 8 ? 6,7,8 MON"
B. "0 30 8 * 6-8 *"
C. "0 30 8 ? 5-8 MON"
D. "0 30 8 ? 6-8 1"

Solution

  1. Step 1: Understand cron fields needed

    Seconds=0, Minutes=30, Hours=8, Day=? (no specific day), Month=6,7,8 (June-Aug), Weekday=MON (Monday)
  2. Step 2: Check options for correct syntax

    "0 30 8 ? 6,7,8 MON" uses '?' for day, lists months as 6,7,8, and weekday as MON, which is correct.
  3. Final Answer:

    "0 30 8 ? 6,7,8 MON" -> Option A
  4. Quick Check:

    Use '?' for day, list months, specify MON weekday [OK]
Hint: Use '?' for day when specifying weekday, list months with commas [OK]
Common Mistakes:
  • Using '*' for day and weekday together
  • Using range '-' instead of commas for months
  • Using numeric weekday instead of MON
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard