0
0
Spring Bootframework~5 mins

@Async for async methods in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @Async annotation do in Spring Boot?
It marks a method to run asynchronously, meaning the method runs in a separate thread without blocking the caller.
Click to reveal answer
beginner
How do you enable @Async support in a Spring Boot application?
Add <code>@EnableAsync</code> annotation to a configuration class or the main application class.
Click to reveal answer
intermediate
What type of return values can an @Async method have?
It can return void, CompletableFuture, Future, or ListenableFuture to handle async results.
Click to reveal answer
intermediate
Why should @Async methods be called from a different bean or class?
Because Spring proxies the bean to run async methods; calling <code>@Async</code> method from the same class bypasses the proxy and runs synchronously.
Click to reveal answer
advanced
What happens if an exception is thrown inside an @Async method?
The exception is not propagated to the caller thread. You need to handle exceptions inside the async method or use a custom AsyncUncaughtExceptionHandler.
Click to reveal answer
Which annotation enables asynchronous method execution in Spring Boot?
A@AsyncSupport
B@AsyncMethod
C@AsyncEnabled
D@EnableAsync
What must you do to make a method run asynchronously using @Async?
AAnnotate the method with @Async
BCall the method from the same class
CReturn a String from the method
DUse @Async on the class only
What is a common return type for an @Async method to handle results?
AString
BCompletableFuture
Cint
Dvoid only
Why might calling an @Async method from the same class not run asynchronously?
ABecause Spring proxies are bypassed in same-class calls
BBecause @Async only works on static methods
CBecause the method must be private
DBecause @Async requires a return value
How can you handle exceptions thrown in an @Async method?
AUse @ExceptionHandler on the method
BExceptions automatically propagate to caller
CUse AsyncUncaughtExceptionHandler or handle inside the method
DExceptions are ignored silently
Explain how to set up and use @Async in a Spring Boot application.
Think about enabling async support, marking methods, and calling them properly.
You got /5 concepts.
    Describe why calling an @Async method from the same class does not run it asynchronously and how to fix it.
    Consider how Spring manages async calls with proxies.
    You got /4 concepts.