What is a cron expression in Spring Boot scheduling?
A cron expression is a string that defines a schedule using six or seven fields to specify seconds, minutes, hours, day of month, month, day of week, and optionally year. Spring Boot uses it to run tasks at specific times.
Click to reveal answer
beginner
What does the cron expression "0 0 12 * * ?" mean in Spring Boot?
It means the task runs every day at 12:00 PM (noon). The fields represent: 0 seconds, 0 minutes, 12 hours, every day of month, every month, any day of week.
Click to reveal answer
intermediate
How many fields are there in a Spring Boot cron expression and what are they?
There are 6 or 7 fields: seconds, minutes, hours, day of month, month, day of week, and optionally year.
Click to reveal answer
intermediate
What does the special character '?' mean in a cron expression?
The '?' character means 'no specific value'. It is used in either day of month or day of week fields to avoid conflicts when one is specified and the other is not.
Click to reveal answer
beginner
How do you schedule a task to run every 5 minutes using a cron expression in Spring Boot?
Use the expression "0 0/5 * * * ?" which means: 0 seconds, every 5 minutes, every hour, every day, every month, any day of week.
Click to reveal answer
How many fields does a Spring Boot cron expression typically have?
A4
B5
C6 or 7
D8
✗ Incorrect
Spring Boot cron expressions have 6 or 7 fields: seconds, minutes, hours, day of month, month, day of week, and optionally year.
What does the cron expression "0 15 10 * * ?" do?
ARuns at 3:10 PM every day
BRuns at 10:15 AM every day
CRuns every 10 minutes
DRuns at 15 minutes past every hour
✗ Incorrect
The expression means 0 seconds, 15 minutes, 10 hours, every day, every month, any day of week, so it runs at 10:15 AM daily.
Which character in a cron expression means 'any value'?
A*
B?
C/
D-
✗ Incorrect
The '*' character means 'any value' for that field in the cron expression.
In Spring Boot cron expressions, what does the '?' character do?
ASpecifies a list of values
BMeans every value
CSpecifies a range
DNo specific value, used to avoid conflicts
✗ Incorrect
The '?' character means no specific value and is used in day of month or day of week fields to avoid conflicts.
How would you write a cron expression to run a task every hour at the 0th minute?
A0 0 * * * ?
B0 * * * * ?
C* 0 * * * ?
D0 0 0 * * ?
✗ Incorrect
The expression "0 0 * * * ?" means 0 seconds, 0 minutes, every hour, every day, every month, any day of week.
Explain the structure of a Spring Boot cron expression and what each field represents.
Think about the time units from smallest to largest and special optional parts.
You got /8 concepts.
Describe how you would schedule a task to run every weekday at 9 AM using a cron expression in Spring Boot.
Use '?' to avoid conflicts and specify weekdays in day of week.
You got /4 concepts.
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
Step 1: Understand the purpose of cron expressions
Cron expressions define timing details for scheduling tasks.
Step 2: Identify what cron expressions control in Spring Boot
They tell Spring Boot exactly when to run a method automatically.
Final Answer:
When a scheduled task should run -> Option B
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?
Hour field is 25, which is outside 0-23 range, causing error.
Final Answer:
Hour value 25 is invalid -> Option C
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
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)
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.
Final Answer:
"0 30 8 ? 6,7,8 MON" -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.