Bird
0
0

You want to schedule two tasks: one runs every 10 seconds, another runs every 15 seconds. How can you ensure they never run at the same time?

hard📝 Application Q9 of 15
Spring Boot - Async Processing
You want to schedule two tasks: one runs every 10 seconds, another runs every 15 seconds. How can you ensure they never run at the same time?
AUse fixedDelay for one and fixedRate for the other with different intervals
BMake both methods synchronized
CUse cron expressions with different seconds values to stagger start times
DUse @Async on both methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand scheduling overlap

    fixedRate and fixedDelay do not guarantee no overlap; synchronized blocks only affect method concurrency.
  2. Step 2: Use cron to control exact start times

    Using cron with different seconds values staggers execution times to avoid overlap.
  3. Final Answer:

    Use cron expressions with different seconds values to stagger start times -> Option C
  4. Quick Check:

    Stagger tasks with cron seconds field = B [OK]
Quick Trick: Cron lets you control exact start seconds to avoid overlap [OK]
Common Mistakes:
  • Assuming fixedDelay/fixedRate prevent overlap
  • Using synchronized without effect on scheduling
  • Using @Async which runs tasks concurrently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes