0
0
Spring Bootframework~10 mins

@EnableAsync annotation in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable asynchronous processing in a Spring Boot application.

Spring Boot
@Configuration
@[1]
public class AsyncConfig {
    @Bean
    public Executor taskExecutor() {
        return Executors.newCachedThreadPool();
    }
}
Drag options to blanks, or click blank then click option'
AEnableScheduling
BAsync
CEnableAsync
DAsyncConfigurer
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Async instead of @EnableAsync on configuration class
Confusing with @EnableScheduling
2fill in blank
medium

Complete the method annotation to mark it for asynchronous execution.

Spring Boot
public class MyService {
    @[1]
    public void process() {
        // long running task
    }
}
Drag options to blanks, or click blank then click option'
AAsync
BEnableAsync
CScheduled
DTransactional
Attempts:
3 left
💡 Hint
Common Mistakes
Using @EnableAsync on methods instead of @Async
Confusing with @Scheduled for async tasks
3fill in blank
hard

Fix the error in the configuration class to properly enable async support.

Spring Boot
@[1]
@Configuration
public class AsyncConfig {
    @Bean
    public Executor taskExecutor() {
        return Executors.newCachedThreadPool();
    }
}
Drag options to blanks, or click blank then click option'
ABean
BAsync
CConfiguration
DEnableAsync
Attempts:
3 left
💡 Hint
Common Mistakes
Placing @EnableAsync on a method instead of the class
Omitting @EnableAsync entirely
4fill in blank
hard

Fill both blanks to create a configuration class that enables async and defines a thread pool executor.

Spring Boot
@[1]
@[2]
public class AsyncConfig {
    @Bean
    public Executor taskExecutor() {
        return Executors.newFixedThreadPool(5);
    }
}
Drag options to blanks, or click blank then click option'
AEnableAsync
BComponent
CConfiguration
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @Configuration
Forgetting @EnableAsync annotation
5fill in blank
hard

Fill all three blanks to define an async method with a custom executor and enable async support.

Spring Boot
@[1]
@[2]
public class AsyncConfig {
    @Bean(name = "customExecutor")
    public Executor taskExecutor() {
        return Executors.newSingleThreadExecutor();
    }
}

public class MyService {
    @[3]("customExecutor")
    public void runTask() {
        // async task
    }
}
Drag options to blanks, or click blank then click option'
AEnableAsync
BConfiguration
CAsync
DComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting @EnableAsync on configuration class
Not specifying executor name in @Async annotation