The TaskExecutor interface is Spring's abstraction for running a Runnable asynchronously. It extends java.util.concurrent.Executor and has a single method, execute(Runnable), so your code asks for work to be run and the implementation decides which thread, pool or strategy does it. This keeps threading policy in configuration instead of scattered across business code.
Spring ships several implementations, including ThreadPoolTaskExecutor and SimpleAsyncTaskExecutor, and it uses a TaskExecutor behind @Async, application events and many other features. The related AsyncTaskExecutor adds submit methods and virtual thread support.
Plain new Thread(...) calls make it hard to cap concurrency, name threads, shut down cleanly or swap strategies in tests. A TaskExecutor bean fixes that. The interface is deliberately tiny:
In Spring 6.1 and later, TaskExecutor is a functional interface, and the richer AsyncTaskExecutor sub-interface provides submit(Runnable), submit(Callable) and submitCompletable.
| Implementation | Behaviour |
|---|---|
ThreadPoolTaskExecutor | Wraps a ThreadPoolExecutor. Configurable core size, max size, queue capacity. The usual production choice. |
SimpleAsyncTaskExecutor | Starts a new thread per task, no pooling. Can use virtual threads with setVirtualThreads(true) (Spring 6.1+). |
SyncTaskExecutor | Runs the task in the calling thread. Useful for tests. |
ConcurrentTaskExecutor | Adapts an existing java.util.concurrent.Executor. |
VirtualThreadTaskExecutor | Runs each task on a new virtual thread (Spring 6.1+). |
The pool starts up to corePoolSize threads, queues further tasks up to queueCapacity, and only then grows toward maxPoolSize. When both are full, the rejection policy runs; CallerRunsPolicy slows the producer down instead of dropping work.
You can inject the executor and call it:
Or enable @Async and name the executor:
@Async only works through the Spring proxy, so calling the method from within the same class bypasses it.
Spring Boot auto-configures an applicationTaskExecutor bean. In Boot 3.2 and later, setting spring.threads.virtual.enabled=true on Java 21 or newer makes that executor use virtual threads, so blocking I/O tasks no longer need a large pool. Pool properties under spring.task.execution.pool.* configure the default ThreadPoolTaskExecutor when virtual threads are off.
TaskExecutor extends Executor and exists to be a Spring-named bean type. It adds no methods, but Spring configures and injects it consistently, and AsyncTaskExecutor adds submit.
Spring looks for a unique TaskExecutor bean, or a bean named taskExecutor. In Spring Boot it is applicationTaskExecutor. Without any, Spring falls back to SimpleAsyncTaskExecutor.
Set setWaitForTasksToCompleteOnShutdown(true) and setAwaitTerminationSeconds(...) on ThreadPoolTaskExecutor.
Use TaskExecutor for simple fire-and-forget work inside Spring applications. Use ExecutorService or structured approaches when you need futures and lifecycle control beyond what Spring wraps.
TaskExecutor decouples what runs asynchronously from how it runs. Define a configured ThreadPoolTaskExecutor (or use virtual threads on Java 21+), inject it where needed, point @Async at it by name, and set a sensible queue, rejection policy and shutdown behaviour.