Bird
0
0

Given the code below, what will be the output behavior?

medium📝 component behavior Q4 of 15
Spring Boot - Async Processing
Given the code below, what will be the output behavior?
@Scheduled(fixedDelay = 2000)
public void task() {
  System.out.println("Running task");
  try { Thread.sleep(3000); } catch (InterruptedException e) {}
}
APrints "Running task" every 5 seconds
BPrints "Running task" every 2 seconds
CPrints "Running task" every 3 seconds
DPrints "Running task" once and stops
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixedDelay with method duration

    fixedDelay waits 2 seconds after method finishes before next run.
  2. Step 2: Calculate total interval

    Method sleeps 3 seconds, then 2 seconds delay, total 5 seconds between prints.
  3. Final Answer:

    Prints "Running task" every 5 seconds -> Option A
  4. Quick Check:

    fixedDelay waits after method ends = D [OK]
Quick Trick: fixedDelay adds delay after method finishes [OK]
Common Mistakes:
  • Ignoring method execution time
  • Confusing fixedDelay with fixedRate
  • Assuming prints happen every 2 seconds

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes