Complete the code to enable asynchronous processing in a Spring Boot application.
@Configuration @[1] public class AsyncConfig { @Bean public Executor taskExecutor() { return Executors.newCachedThreadPool(); } }
The @EnableAsync annotation activates Spring's asynchronous method execution capability.
Complete the method annotation to mark it for asynchronous execution.
public class MyService { @[1] public void process() { // long running task } }
The @Async annotation marks a method to run asynchronously.
Fix the error in the configuration class to properly enable async support.
@[1] @Configuration public class AsyncConfig { @Bean public Executor taskExecutor() { return Executors.newCachedThreadPool(); } }
The @EnableAsync annotation must be placed on the configuration class to enable async processing.
Fill both blanks to create a configuration class that enables async and defines a thread pool executor.
@[1] @[2] public class AsyncConfig { @Bean public Executor taskExecutor() { return Executors.newFixedThreadPool(5); } }
The class must be annotated with @Configuration to define beans and @EnableAsync to activate async support.
Fill all three blanks to define an async method with a custom executor and enable async support.
@[1] @[2] public class AsyncConfig { @Bean(name = "customExecutor") public Executor taskExecutor() { return Executors.newSingleThreadExecutor(); } } public class MyService { @[3]("customExecutor") public void runTask() { // async task } }
The configuration class needs @Configuration and @EnableAsync. The async method uses @Async with the custom executor name.