AsyncConfigurer is the Spring interface you implement to configure @Async in one place. It has two methods: getAsyncExecutor() supplies the executor that runs @Async methods, and getAsyncUncaughtExceptionHandler() supplies the handler for exceptions thrown by void async methods. Both are default methods, so you override only what you need.
It matters because without it you get the framework defaults, which means no say over thread limits and only log output for failed fire-and-forget tasks.
The interface lives in org.springframework.scheduling.annotation. Spring consults it when @EnableAsync is processed:
| Method | Purpose | Default if not overridden |
|---|---|---|
getAsyncExecutor() | The Executor that runs methods annotated with plain @Async | null, so Spring looks for a TaskExecutor bean, then falls back to SimpleAsyncTaskExecutor |
getAsyncUncaughtExceptionHandler() | Handles exceptions from void async methods | SimpleAsyncUncaughtExceptionHandler, which logs the error |
It does not configure timeouts. Timeouts are handled by the futures you return (for example CompletableFuture.orTimeout(...)) or by the code inside the task, not by this interface.
Return a configured pool. Because this executor is not a Spring-managed bean unless you also expose it, call initialize() yourself.
The pool starts with 5 threads and queues up to 25 waiting tasks. Only when the queue is full does it grow toward 10 threads. When all 10 threads are busy and the queue is full, new tasks are rejected with a TaskRejectedException by default, which is the signal you want under overload.
Do not put @Bean on getAsyncExecutor(). Turning the executor into a bean makes Spring manage and shut it down properly, but it can also change which executor other framework code picks up. If you want a managed bean, define it as a separate @Bean method and return it from getAsyncExecutor().
An exception thrown by a void async method has no caller to receive it. This handler is where it lands.
Register it in the configurer:
Avoid logging the raw parameter values if they can contain personal data or secrets. Logging the count or an identifier is safer.
The handler is not used for methods that return a Future or CompletableFuture. In that case the exception is stored in the future, and the caller sees it from get(), join() or exceptionally(...).
You have several ways to choose an executor. AsyncConfigurer is not always the best one.
spring.task.execution.*) are the simplest choice when one tuned pool is enough.Executor bean plus @Async("name") is best when different tasks need different pools.AsyncConfigurer fits when you want the default executor and the uncaught-exception handler defined together in code, especially outside Boot.In Boot, defining an AsyncConfigurer bean is also the way to set a global exception handler for void methods, since there is no property for it.
No. @EnableAsync alone is enough. You add AsyncConfigurer only to customise the default executor or the uncaught-exception handler.
No. Those exceptions are carried by the future. The handler only covers void methods.
Yes. A method with an explicit executor name uses that executor, and a plain @Async method uses the one from getAsyncExecutor().
It can, but you then manage its lifecycle in the container. If you create the pool inside the method, call initialize() and set shutdown behaviour yourself.
AsyncConfigurer centralises two decisions for @Async: which executor runs your tasks and what happens when a void task fails. Implement it on a @Configuration class with @EnableAsync, size the pool deliberately, handle uncaught exceptions with a logging or alerting handler, and use futures for results and timeouts.