The @Async annotation tells Spring to run a bean method on a separate thread from a TaskExecutor, so the caller returns immediately instead of waiting. You use it for slow, independent work such as sending email, calling a remote API or generating a report. It only works when @EnableAsync is active and the method is called through the Spring proxy.
The method can return void, a Future or a CompletableFuture. Anything else is not supported, because the caller has already moved on by the time the result exists.
Spring does not change your method. When @EnableAsync is present, Spring wraps every bean that has @Async methods in a proxy. A call that goes through the proxy is packaged as a task and submitted to an executor. The proxy returns to the caller right away, while the real method runs later on a pool thread.
This has three practical consequences:
public on a Spring-managed bean. A private method or an object created with new is never made asynchronous.SecurityContext and request-scoped beans does not follow it automatically.Add @EnableAsync to one configuration class. In Spring Boot this is usually the main class or a small dedicated config.
Without this annotation @Async is silently ignored and the method runs on the caller's thread. That is the most common reason an "async" method seems to do nothing.
A method that returns a result should return a CompletableFuture. Use CompletableFuture.completedFuture(...) to hand back the value. (ListenableFuture is the old Spring-specific type; it was deprecated in Spring Framework 6 and should not be used in new code.)
The caller composes the futures instead of blocking on each one:
Both reports take about two seconds in total, not four, because they run on two pool threads at the same time.
The executor decides how many threads run your tasks, so it matters in production.
| Setup | Executor used |
|---|---|
| Plain Spring with no executor bean | SimpleAsyncTaskExecutor, which starts a new thread per task and does not pool |
| Spring Boot (auto-configuration) | applicationTaskExecutor, a ThreadPoolTaskExecutor tuned with spring.task.execution.* properties |
Spring Boot 3.2+ with spring.threads.virtual.enabled=true | A SimpleAsyncTaskExecutor that starts a virtual thread per task |
A bean you define and name in @Async("name") | That bean |
With Spring Boot you can tune the default pool from application.properties without writing code:
For several workloads with different limits, define separate executors and select one by name:
A bounded queue plus a rejection policy protects the application. An unbounded queue can hide an overload until the JVM runs out of memory.
An exception in a CompletableFuture method is captured in the future, so it surfaces when the caller calls join(), get() or attaches exceptionally(...). An exception in a void method has no caller to receive it. Spring passes it to an AsyncUncaughtExceptionHandler, which logs it by default. Register your own through the AsyncConfigurer interface:
@Async method from the same class. Move it to another bean.@EnableAsync. The method runs synchronously and nothing warns you.String. The caller would receive null; return CompletableFuture<String>.@Transactional or the security context in the async method. A transaction started by the caller is not shared, and the security context needs a delegating executor such as DelegatingSecurityContextAsyncTaskExecutor.Yes. Add @EnableAsync to a configuration class. Without Boot there is no auto-configured pool, so Spring falls back to SimpleAsyncTaskExecutor unless you define an executor bean.
Usually because @EnableAsync is missing, the method is called from within the same class, or the object was created with new instead of being injected. Each of these skips the proxy.
Yes, but it gets its own transaction on its own thread. The caller's transaction does not extend to it, so do not expect to see uncommitted data from the caller.
They combine well. On Java 21+ with Spring Boot 3.2+, enabling virtual threads makes @Async start a cheap virtual thread per task. You still use @Async to say which work runs in the background.
@Async moves a method onto an executor thread through a Spring proxy. Enable it with @EnableAsync, return void or CompletableFuture, call the method from another bean, and choose or size the executor explicitly. Handle errors through the returned future or an AsyncUncaughtExceptionHandler, and remember that transactions and the security context do not cross the thread boundary.