In Spring Boot, a task executor is auto-configured for you as the applicationTaskExecutor bean, and you tune it with spring.task.execution.* properties. For full control, define your own ThreadPoolTaskExecutor bean and reference it from @Async. On Java 21 or later with Spring Boot 3.2+, you can instead set spring.threads.virtual.enabled=true to run tasks on virtual threads.
A task executor decouples work from the calling thread, so it is the foundation for @Async methods, scheduled jobs and background processing. Choosing the pool size and queue carefully matters, because an unbounded queue or pool can exhaust memory or threads under load.
When Spring Boot finds no Executor bean of its own, it creates applicationTaskExecutor, a ThreadPoolTaskExecutor. You configure it entirely from application.yml:
Spring Boot also applies this executor to @Async methods and Spring MVC asynchronous request handling once @EnableAsync is present.
A ThreadPoolTaskExecutor does not add threads in the order many developers expect.
core-size threads are created as tasks arrive.queue-capacity is reached.max-size.So with an unbounded queue (the default capacity is Integer.MAX_VALUE), the pool never grows past the core size. Set a finite queue-capacity if you want max-size to take effect.
Declare your own executor when you need different pools for different workloads, or a custom rejection policy:
CallerRunsPolicy makes the submitting thread run the task when the pool is saturated, which naturally slows producers (back pressure) instead of dropping work. Beans of type ThreadPoolTaskExecutor created by new do not need initialize() called manually when declared as a bean, because Spring calls it.
Name the executor in the annotation to pick a pool:
@Async works through a proxy, so it has no effect when you call the method from within the same class. Return void, Future or CompletableFuture, and handle exceptions: for void methods, implement an AsyncUncaughtExceptionHandler through AsyncConfigurer, because the caller never sees the exception.
If you define more than one Executor bean, Spring Boot's auto-configuration backs off and @Async without a name may fail to choose. Mark one as the default, or implement AsyncConfigurer:
With Spring Boot 3.2 or newer on Java 21 or later, one property switches task execution to virtual threads:
The auto-configured applicationTaskExecutor then creates a new virtual thread per task and Tomcat handles requests on virtual threads. This suits blocking I/O such as database and HTTP calls, and removes the need to size a pool. It does not help CPU-bound work, and you should still bound concurrency to downstream resources, for example with a semaphore or a connection pool limit.
@Scheduled tasks do not use the async executor. Spring Boot provides a ThreadPoolTaskScheduler configured by spring.task.scheduling.pool.size, which defaults to one thread, so long jobs can delay each other:
Because the queue is unbounded by default. Threads beyond the core size are created only when the queue is full, so set a finite queue-capacity.
@EnableAsync in Spring Boot?Yes, for @Async methods. The executor is auto-configured, but asynchronous method execution is enabled only with that annotation.
The rejection policy decides. The default throws TaskRejectedException. CallerRunsPolicy runs the task on the caller thread.
For blocking I/O workloads on Java 21 or later, usually yes. Keep a bounded pool for CPU-bound work.
Spring Boot gives you a tunable applicationTaskExecutor through spring.task.execution.*. Define custom ThreadPoolTaskExecutor beans for separate workloads, size the core, queue and maximum deliberately, choose a rejection policy, shut down gracefully, and consider virtual threads for blocking I/O.