Bird
0
0

What is wrong with this custom thread pool configuration in Spring Boot?

medium📝 Debug Q14 of 15
Spring Boot - Async Processing
What is wrong with this custom thread pool configuration in Spring Boot?
@Bean
public ThreadPoolTaskExecutor taskExecutor() {
  ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  executor.setCorePoolSize(5);
  executor.setMaxPoolSize(3);
  executor.setQueueCapacity(10);
  executor.initialize();
  return executor;
}
AMissing @EnableAsync annotation on configuration class
BQueue capacity cannot be set in ThreadPoolTaskExecutor
CCore pool size is greater than max pool size, which is invalid
DThreadPoolTaskExecutor cannot be returned as a bean
Step-by-Step Solution
Solution:
  1. Step 1: Check core and max pool size relationship

    Core pool size must be less than or equal to max pool size; here core is 5 but max is 3, which is invalid.
  2. Step 2: Validate other settings

    Queue capacity is valid; @EnableAsync is optional but recommended; returning ThreadPoolTaskExecutor bean is correct.
  3. Final Answer:

    Core pool size is greater than max pool size, which is invalid -> Option C
  4. Quick Check:

    Core pool ≤ max pool required [OK]
Quick Trick: Core pool size must not exceed max pool size [OK]
Common Mistakes:
  • Setting core pool size larger than max pool size
  • Assuming queue capacity is mandatory to set
  • Forgetting to add @EnableAsync (not always required)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes