Bird
0
0

Given this code snippet, what will be the output if the service fails 5 times and the failure rate threshold is 50%?

medium📝 Predict Output Q4 of 15
Spring Boot - Advanced Patterns
Given this code snippet, what will be the output if the service fails 5 times and the failure rate threshold is 50%?
@CircuitBreaker(name = "myService", fallbackMethod = "fallback")
public String callService() {
  // service call that fails 5 times
}
AThe service will continue to be called without fallback
BThe circuit breaker will reset immediately
CAn exception will be thrown without fallback
DThe fallback method will be called after threshold is reached
Step-by-Step Solution
Solution:
  1. Step 1: Understand failure rate threshold effect

    With 5 failures and threshold 50%, the failure rate exceeds threshold, so circuit breaker opens.
  2. Step 2: Effect on method calls after threshold

    Once open, calls trigger fallback method instead of the failing service.
  3. Final Answer:

    The fallback method will be called after threshold is reached -> Option D
  4. Quick Check:

    Failure rate > threshold triggers fallback [OK]
Quick Trick: Fallback triggers when failure rate exceeds threshold [OK]
Common Mistakes:
  • Assuming service keeps failing without fallback
  • Expecting immediate reset of circuit breaker
  • Ignoring fallback method usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes