Why this matters
- Traditional servlet containers allocate one platform thread per request — under load, thousands of threads waiting on database or payment calls waste memory and context-switch time.
- Virtual threads are lightweight: blocking on I/O releases the underlying carrier thread so another virtual thread can run, giving you reactive-style concurrency with blocking code.
- Spring Boot 3.2+ enables virtual threads for Tomcat,
@Async, and scheduled tasks with a single property — no rewrite to WebFlux required.
Virtual threads
L1 · FresherLightweight threads on Java 21 let Tomcat handle many concurrent blocking requests with fewer OS threads.
Enabling in Boot 3.5
L2 · IntermediateSet spring.threads.virtual.enabled=true (and use supported embedded server) for platform thread savings.
Pinning awareness
L3 · AdvancedSynchronized blocks or native code can pin virtual threads to carriers — profile before claiming infinite scale.
vs WebFlux
L4 · ExpertVirtual threads simplify blocking JDBC and MVC code; reactive stacks still win for streaming and backpressure-heavy workloads.
Where Boot enables virtual threads
spring.threads.virtual.enabled=true— switches Tomcat's request handling to virtual threads.@Asyncexecutor — auto-configured to use virtual threads when the property is set.@Scheduledtasks — run on virtual threads in the same configuration.- Carrier pool — a small set of platform threads that multiplex many virtual threads.
- Pinning — when code holds a monitor (
synchronized) or uses native code during I/O, the virtual thread pins its carrier.
Blocked virtual threads release their carrier — other virtual threads continue
Enable virtual threads
spring:
threads:
virtual:
enabled: true
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 3 sections
- Verify with a diagnostic endpoint
- Custom executor for background work
- When virtual threads are not enough
Test yourself
Answer these before moving on — recall is what makes it stick.