Spring Boot Async method not running in separate Thread
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
A frequent Spring Boot issue is adding @Async to a method and finding it still runs on the caller thread. This usually happens because async proxying is not active, method invocation bypasses the proxy, or executor configuration is missing. Correct async behavior requires both annotation setup and call-path design.
Enable Async Infrastructure First
@Async works through Spring proxies, so the application must enable async support.
Without @EnableAsync, methods annotated with @Async run normally and can appear to ignore async intent.
Use @Async in a Separate Spring Bean
Self-invocation is the most common mistake. If a class calls its own @Async method directly, proxy interception is bypassed.
Call this method from another Spring-managed bean, not from this.sendEmail(...) inside the same class.
Configure a Dedicated Async Executor
Default executors may be too limited or unclear for production diagnostics. Define an explicit executor bean.
Then reference it:
Named thread prefixes make thread behavior easy to confirm in logs.
Return Types and Error Handling
@Async methods can return void, Future, or CompletableFuture. For observability, CompletableFuture is usually better.
For void async methods, exceptions can be lost without explicit handling. Register async exception handlers where needed.
Verify Thread Behavior in Tests
Add tests or logs that assert async call actually leaves request thread.
If both logs show same thread name repeatedly, check for self-invocation or missing proxy setup.
For integration tests, use Awaitility or CompletableFuture joins instead of arbitrary sleeps.
Transaction and Context Considerations
Async methods run in separate threads, so thread-local context and transaction boundaries may not propagate as expected. If async operation needs database consistency, define transaction strategy explicitly inside async method.
Also be careful with request-scoped objects and security context assumptions in async tasks.
Practical Debugging Checklist
If async behavior is still not visible, use a quick checklist:
- confirm bean is discovered by component scanning
- verify method is
publicand notprivate - check whether class or method is
finalin proxy-sensitive setups - log executor thread name and pool stats during calls
These checks usually identify configuration gaps faster than random code changes.
Common Pitfalls
- Forgetting
@EnableAsyncand expecting annotation-only behavior. - Calling
@Asyncmethod from same class and bypassing proxy. - Using default executor without capacity tuning or visibility.
- Returning
voidwithout exception handling strategy. - Assuming transaction and thread-local context automatically propagate.
Summary
- '
@Asyncdepends on Spring proxying, not direct method execution.' - Ensure async support is enabled and method is invoked through another bean.
- Configure a named thread pool executor for control and observability.
- Prefer
CompletableFuturewhen result tracking or error handling is needed. - Validate behavior with thread-name logging and integration tests.
- Treat async configuration and call-path design as one unit during code review.
- Recheck executor sizing under production load to avoid queue backlogs.
Related reading
- Spring Cancel Async Task
- Spring Kafka asynchronous send calls block
- Spring Kafka is Acknowledgement.acknowledge thread safe?
- spring kafka thorws InstanceAlreadyExistsException exception after setting concurrency > 1
- Spring Boot Authentication for Integration Tests
- Spring Boot auto configuration for datasource
- Spring Boot Cannot access REST Controller on localhost 404
- Spring Boot Cannot access REST Controller on localhost 404

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.