0
0
Spring Bootframework~5 mins

@EnableAsync annotation in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @EnableAsync annotation in Spring Boot?
The @EnableAsync annotation tells Spring Boot to enable support for running methods asynchronously, meaning those methods can run in the background without blocking the main thread.
Click to reveal answer
beginner
How do you mark a method to run asynchronously after enabling @EnableAsync?
You add the @Async annotation to the method you want to run asynchronously. This tells Spring to run that method in a separate thread.
Click to reveal answer
intermediate
Where should you place the @EnableAsync annotation in a Spring Boot application?
You usually place <code>@EnableAsync</code> on a configuration class or the main application class to enable asynchronous processing across the app.
Click to reveal answer
advanced
What happens if you call an <code>@Async</code> method from within the same class without going through Spring's proxy?
The @Async method will not run asynchronously because Spring uses proxies to manage async calls. Calling it internally bypasses the proxy, so it runs synchronously.
Click to reveal answer
intermediate
Can you customize the thread pool used by @EnableAsync? How?
Yes, you can customize the thread pool by defining a TaskExecutor bean and specifying it in the @Async annotation or by overriding the default executor in the configuration.
Click to reveal answer
What does the @EnableAsync annotation do in a Spring Boot app?
AEnables asynchronous method execution
BDisables asynchronous processing
CEnables synchronous method execution
DConfigures database connections
Which annotation marks a method to run asynchronously after enabling @EnableAsync?
A@Async
B@AsyncMethod
C@EnableAsyncMethod
D@RunAsync
Where is the best place to put the @EnableAsync annotation?
AOn every asynchronous method
BOn the controller methods only
COn the database entity classes
DOn a configuration or main application class
What happens if you call an @Async method from the same class internally?
AIt causes a compile error
BIt runs asynchronously as expected
CIt runs synchronously, not asynchronously
DIt throws a runtime exception
How can you customize the thread pool used by @EnableAsync?
ABy setting a property in <code>application.properties</code> only
BBy defining a custom <code>TaskExecutor</code> bean
CBy adding <code>@ThreadPool</code> annotation
DYou cannot customize the thread pool
Explain how @EnableAsync and @Async work together in Spring Boot to run methods asynchronously.
Think about how Spring knows which methods to run in the background.
You got /4 concepts.
    Describe a common pitfall when calling an @Async method from within the same class and how to avoid it.
    Consider how Spring manages async calls behind the scenes.
    You got /4 concepts.