Bird
0
0

Why does this scheduled method cause an error?

medium📝 Debug Q7 of 15
Spring Boot - Async Processing
Why does this scheduled method cause an error?
@Scheduled(fixedRate = 1000)
private void doWork() {
  System.out.println("Working");
}
AMethod cannot print to console
BfixedRate cannot be less than 5000
CScheduled methods must be public
DMethod must return boolean
Step-by-Step Solution
Solution:
  1. Step 1: Check method visibility requirements

    Scheduled methods must be public so Spring can proxy and call them.
  2. Step 2: Validate other options

    fixedRate can be any positive number, return type can be void, printing is allowed.
  3. Final Answer:

    Scheduled methods must be public -> Option C
  4. Quick Check:

    Scheduled methods require public visibility = D [OK]
Quick Trick: Make scheduled methods public for Spring to call them [OK]
Common Mistakes:
  • Using private or protected methods
  • Assuming fixedRate minimum value
  • Expecting return values from scheduled methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes