The @Async annotation tells Spring to run a method on a separate thread from a task executor instead of the caller's thread. The caller gets control back immediately, and the method's work finishes in the background. In Spring Boot you enable it with @EnableAsync on a configuration class, and it is best suited to slow, independent work such as sending email, calling remote APIs or generating reports.
An async method must return void or a CompletableFuture (a Future also works) so Spring can hand back a result placeholder.
@EnableAsync registers a post-processor that wraps beans containing @Async methods in a proxy. When a caller invokes the method through the proxy, the proxy submits the call to a TaskExecutor and returns right away. Because it is proxy based, the usual proxy rules apply:
@Async method with this. inside the same class runs it synchronously.public and not final or static.Spring MVC understands a returned CompletableFuture and releases the servlet thread while the work runs. The controller method itself runs on the request thread, and only buildReport runs on the executor.
Spring Boot auto-configures a ThreadPoolTaskExecutor named applicationTaskExecutor and @Async uses it. You can tune it through properties:
On Java 21 and later with Spring Boot 3.2+, set spring.threads.virtual.enabled=true and the auto-configured executor runs tasks on virtual threads, which suits blocking I/O.
For separate pools, define named executors and pick one per method:
Bound the queue. An unbounded queue hides overload until memory runs out.
A void async method cannot throw to its caller. Handle failures explicitly:
CompletableFuture results, use exceptionally or handle, and the exception is also available when you call join() or get().void methods, implement AsyncConfigurer and return an AsyncUncaughtExceptionHandler.Other points to remember:
| Pitfall | Effect |
|---|---|
| Self-invocation | The method runs synchronously, no new thread |
Missing @EnableAsync | @Async is silently ignored |
@Transactional and @Async together | The async method gets its own transaction, not the caller's |
| Security and request context | SecurityContext and request-scoped beans are not propagated by default |
| Application shutdown | Queued tasks can be lost unless you set spring.task.execution.shutdown.await-termination=true |
| Option | Use when |
|---|---|
@Async | Fire-and-forget or simple background work inside one service |
CompletableFuture.supplyAsync with your executor | You want explicit control and no proxy |
@Scheduled | The work is time based, not triggered by a call |
| Message broker | Work must be durable and survive restarts |
| Virtual threads with plain blocking code | You want concurrency without async APIs |
It can return void, Future or CompletableFuture. Returning another type is not supported and the caller would get null.
Yes. Boot auto-configures the executor but does not turn on @Async processing for you, so add @EnableAsync to a configuration class.
Most often the call comes from the same class, so the proxy is bypassed. Move the method into another bean.
By default Boot's applicationTaskExecutor. Name another executor with @Async("name").
@Async moves a bean method onto a task executor so callers do not block. Enable it with @EnableAsync, return CompletableFuture when you need a result, configure a bounded executor, and handle exceptions yourself, because the caller cannot see them. Respect proxy rules and use a broker for work that must not be lost.