Bird
0
0

Why does this custom thread pool configuration cause a runtime error? @Bean public Executor taskExecutor() { return Executors.newCachedThreadPool(); } // Elsewhere @Async uses this executor

medium📝 Debug Q7 of 15
Spring Boot - Async Processing
Why does this custom thread pool configuration cause a runtime error? @Bean public Executor taskExecutor() { return Executors.newCachedThreadPool(); } // Elsewhere @Async uses this executor
AnewCachedThreadPool returns ExecutorService, not ThreadPoolTaskExecutor
BExecutor bean must be named 'threadPoolTaskExecutor'
CMissing @EnableAsync annotation
DnewCachedThreadPool does not limit thread count, causing overload
Step-by-Step Solution
Solution:
  1. Step 1: Understand newCachedThreadPool behavior

    It creates threads as needed without limit, risking overload.
  2. Step 2: Identify runtime risk with unbounded threads

    Unbounded threads can exhaust resources causing runtime errors.
  3. Final Answer:

    newCachedThreadPool does not limit thread count, causing overload -> Option D
  4. Quick Check:

    Unbounded thread pools risk runtime errors [OK]
Quick Trick: Avoid unbounded thread pools for async tasks [OK]
Common Mistakes:
  • Confusing return type mismatch with runtime error cause
  • Assuming missing @EnableAsync causes runtime error here
  • Believing bean name must be specific

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes