Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 55
Async Processing
Some work shouldn't block the request: sending emails, generating thumbnails, calling slow third parties.
Course progress0%
Focus
3 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Some work shouldn't block the request: sending emails, generating thumbnails, calling slow third parties. @Async off-loads to a thread pool; for heavy workloads graduate to message queues.
Informative example
ts
@Configuration @EnableAsyncpublic class AsyncConfig {@Bean(name = "taskExecutor")public ThreadPoolTaskExecutor exec() {var ex = new ThreadPoolTaskExecutor();ex.setCorePoolSize(8);ex.setMaxPoolSize(32);ex.setQueueCapacity(500);ex.setThreadNamePrefix("acme-async-");ex.initialize();return ex;}}@Servicepublic class AuditService {@Asyncpublic CompletableFuture<Void> record(AuditEvent e) {audits.save(e);return CompletableFuture.completedFuture(null);}}
Best practices
- Configure your own executor; the default unbounded pool is dangerous.
@Asynconly works across Spring proxies — same-class calls don't async.- For reliability, use a queue (Kafka, RabbitMQ, SQS), not in-process async.
Ready to mark this lesson complete?Track your journey across the entire course.