Bird
0
0

You want to customize the thread pool used by @Async methods. Which of the following is the correct way to do this?

hard📝 Application Q8 of 15
Spring Boot - Async Processing
You want to customize the thread pool used by @Async methods. Which of the following is the correct way to do this?
ADefine a bean of type Executor and override getAsyncExecutor() in AsyncConfigurer.
BAdd @Async("customExecutor") on methods without any bean definition.
CUse @EnableAsync with a threadPoolSize attribute.
DConfigure thread pool in application.properties only.
Step-by-Step Solution
Solution:
  1. Step 1: Understand async executor customization

    Implement AsyncConfigurer and override getAsyncExecutor() to provide custom Executor bean.
  2. Step 2: Evaluate other options

    @Async("customExecutor") requires a bean named customExecutor; no threadPoolSize attribute exists on @EnableAsync; properties alone are insufficient.
  3. Final Answer:

    Define a bean of type Executor and override getAsyncExecutor() in AsyncConfigurer. -> Option A
  4. Quick Check:

    Custom executor via AsyncConfigurer bean override [OK]
Quick Trick: Override getAsyncExecutor() to customize thread pool [OK]
Common Mistakes:
  • Expecting threadPoolSize on @EnableAsync
  • Not defining Executor bean
  • Relying only on properties

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes