Skip to main content
PreparationZone Logo
PrepZone

Virtual Threads in Boot 3.5

Enable virtual threads for Tomcat, @Async and scheduled tasks on Java 21.

Pass checkpoint below

Read these first

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 · Fresher

Lightweight threads on Java 21 let Tomcat handle many concurrent blocking requests with fewer OS threads.

Enabling in Boot 3.5

L2 · Intermediate

Set spring.threads.virtual.enabled=true (and use supported embedded server) for platform thread savings.

Pinning awareness

L3 · Advanced

Synchronized blocks or native code can pin virtual threads to carriers — profile before claiming infinite scale.

vs WebFlux

L4 · Expert

Virtual 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.
  • @Async executor — auto-configured to use virtual threads when the property is set.
  • @Scheduled tasks — 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.
Platform threads (carriers)
VT-1Blocked on I/O
VT-2Running
VT-3Blocked on I/O

Blocked virtual threads release their carrier — other virtual threads continue

Thousands of virtual threads multiplex onto a small pool of platform (carrier) threads.

Enable virtual threads

Java
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.