Bird
0
0

Why might this Micrometer Timer code not record the duration as expected?

medium📝 Debug Q7 of 15
Spring Boot - Actuator
Why might this Micrometer Timer code not record the duration as expected?
Timer timer = Timer.builder("task.duration")
  .register(meterRegistry);
timer.record(() -> { throw new IllegalStateException(); });
ATimer requires a return value from the lambda
BThe exception interrupts timing, so duration is not recorded
CTimer cannot be registered without a description
DIllegalStateException is not supported by Timer
Step-by-Step Solution
Solution:
  1. Step 1: Understand Timer.record behavior

    Timer records duration of successful execution.
  2. Step 2: Effect of exception

    Exception thrown interrupts execution, so timing is aborted.
  3. Final Answer:

    The exception interrupts timing, so duration is not recorded -> Option B
  4. Quick Check:

    Exceptions prevent Timer from recording [OK]
Quick Trick: Exceptions stop Timer from recording duration [OK]
Common Mistakes:
  • Assuming Timer records even if exception occurs
  • Thinking description is mandatory for registration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes