@Async tells Spring to run a method on a separate thread so the caller does not wait for it. Spring wraps the bean in a proxy that submits each call to a TaskExecutor. It suits slow, independent work such as sending email, calling remote APIs or generating reports. You must also enable it with @EnableAsync.
Add @EnableAsync to a configuration class, then annotate public methods of Spring beans.
When a controller calls sendWelcomeEmail, the call returns immediately and the work continues on an executor thread.
A void method gives you no result and no way to see failures. To get a result, return CompletableFuture<T>. Older code used Future or ListenableFuture; CompletableFuture is the current choice.
Both reports are built in parallel, and join() waits for both.
By default Spring Boot configures a ThreadPoolTaskExecutor named applicationTaskExecutor. Define your own to set sizes, a thread name prefix and a rejection policy.
Then pick it per method with @Async("mailExecutor"). Separate executors stop one slow task type from starving others. Without a bounded queue and sensible limits, a burst can exhaust memory or threads. In Spring Boot 3.2 and later with Java 21, set spring.threads.virtual.enabled=true to run async work on virtual threads, which suits blocking I/O.
Exceptions from a void method are not propagated to the caller. Register an AsyncUncaughtExceptionHandler by implementing AsyncConfigurer.
For methods returning CompletableFuture, the exception completes the future exceptionally, so use exceptionally or handle on the caller side.
final, and the bean must be managed by Spring.@Async on a @Transactional method runs in a new thread and so in a new transaction context. The caller's transaction does not carry over.SecurityContext, do not follow to the new thread unless you configure propagation.void, Future or CompletableFuture. Other types would always yield null.Usually @EnableAsync is missing, or the method is called from within the same class so the proxy is bypassed.
No. It uses threads from the configured executor, so thread count is bounded by that pool.
Yes, but the async method gets its own transaction on its own thread. Do not expect it to join the caller's transaction.
Wait on the returned CompletableFuture, or use Awaitility. Test with a synchronous executor when you only need the logic.
@Async moves a method call to another thread, so slow work does not block the caller. Enable it with @EnableAsync, return CompletableFuture when you need results, configure a bounded executor and handle exceptions explicitly. Avoid self-invocation and remember that transactions and security context do not carry across threads.