@Async is a Spring annotation that makes a method run on a separate thread, so the caller returns immediately instead of waiting. It works through a proxy: you enable it with @EnableAsync, annotate a public method on a Spring bean, and Spring submits each call to a TaskExecutor. The method can return void, a Future, or a CompletableFuture.
It is meant for work whose result the caller does not need right away, such as sending email, calling a slow external service or writing audit records.
Turn on async processing once in a configuration class:
Then annotate the method:
The caller continues without waiting. Without @EnableAsync, the annotation is ignored and the method runs synchronously.
| Return type | Behaviour |
|---|---|
void | Fire and forget; exceptions cannot reach the caller |
Future<T> | Caller can block with get() |
CompletableFuture<T> | Caller can compose with thenApply, thenCombine, exceptionally |
CompletableFuture is the usual choice today:
By default Spring uses a TaskExecutor. In Spring Boot, a ThreadPoolTaskExecutor named applicationTaskExecutor is auto-configured and tuned with spring.task.execution.* properties. Outside Boot, Spring falls back to a SimpleAsyncTaskExecutor, which starts a new thread per task and does not pool. For production, define your own bounded pool:
On Java 21 and later with Spring Boot 3.2 or newer, set spring.threads.virtual.enabled=true to have the auto-configured executor use virtual threads, which suits blocking I/O work.
An exception in a void async method never reaches the caller. Register a handler:
For CompletableFuture methods, handle failures with exceptionally or handle on the returned future.
@Async method from another method of the same class bypasses the proxy and runs synchronously. Call it from another bean.final or static for the proxy to intercept it.@Transactional does not carry over to the new thread, and thread-local data such as the SecurityContext is lost unless you configure propagation.setWaitForTasksToCompleteOnShutdown(true) so queued tasks are not dropped when the application stops.Usually @EnableAsync is missing, the call is made from within the same class, or the method is not public. All three bypass the proxy.
The executor bean named taskExecutor or the single TaskExecutor in the context; in Boot that is applicationTaskExecutor. You can choose another by naming it in @Async("name").
Yes, wrap it in CompletableFuture<T> or Future<T>. A plain return type other than void or a future is not supported.
No. @Async moves a call to another thread; @Scheduled triggers a method on a timer. They can be combined.
@Async runs Spring bean methods on an executor thread so callers do not block. Enable it with @EnableAsync, return CompletableFuture when you need a result, use a bounded executor, and handle errors explicitly. Most problems come from proxy rules and from state that does not follow the call onto the new thread.