Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable asynchronous execution of the method.
Spring Boot
@[1]
public void sendEmail() {
// email sending logic
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Transactional instead of @Async
Forgetting to enable async support in configuration
✗ Incorrect
The @Async annotation marks the method to run asynchronously in Spring Boot.
2fill in blank
mediumComplete the code to enable async support in the Spring Boot application.
Spring Boot
@Configuration @Enable[1] public class AsyncConfig { }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @EnableScheduling instead of @EnableAsync
Not adding this annotation causes @Async to be ignored
✗ Incorrect
The @EnableAsync annotation enables Spring's asynchronous method execution capability.
3fill in blank
hardFix the error in the async method declaration to return a Future result.
Spring Boot
@Async public [1]<String> processData() { // processing logic return new AsyncResult<>("done"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning void when a Future is expected
Using incompatible return types like Callable
✗ Incorrect
The method should return java.util.concurrent.Future to work with @Async and AsyncResult.
4fill in blank
hardFill both blanks to correctly configure a custom executor for async methods.
Spring Boot
@Bean public Executor [1]() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.setMaxPoolSize(10); executor.setQueueCapacity(25); executor.initialize(); return [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a different variable name than created
Using inconsistent method names
✗ Incorrect
The method name is taskExecutor and the returned object is executor.
5fill in blank
hardFill all three blanks to correctly annotate and configure async method with custom executor.
Spring Boot
@Async([1]) public void runTask() { // task logic } @Bean public Executor [2]() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(3); executor.setMaxPoolSize(6); executor.setQueueCapacity(10); executor.initialize(); return [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string in @Async
Mismatching bean method name and returned variable
✗ Incorrect
The @Async annotation references the executor bean name as a string, the bean method is named taskExecutor, and the returned variable is executor.