Quick revision
The short answer
In Spring Boot 3.2 and later, spring.threads.virtual.enabled=true switches the supported executors, such as Tomcat's request threads and the default task executor, to virtual threads. Before enabling it, I check for synchronized blocks around blocking calls, which pin the carrier thread on Java 21 (JDK 24 removed most of this pinning), for ThreadLocal-heavy code that will now create a copy per task, and for connection pools, which become the real limit once there are thousands of concurrent threads. After enabling it, I load test and watch JFR events such as jdk.VirtualThreadPinned, pool wait times and latency before rolling out.
What to remember
In this answer, we saw that spring.threads.virtual.enabled=true in Spring Boot 3.2 and later moves Tomcat, Jetty and the default task executor to virtual threads, which removes the thread pool as an accidental concurrency limit. Before enabling it, we look for synchronized around blocking calls, which pin carriers on Java 21 but mostly not since JDK 24, size connection pools and add explicit limits, and remove ThreadLocal caches. After enabling it, we load test with JFR events such as jdk.VirtualThreadPinned and roll out gradually while comparing latency, errors and resource use.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In Spring Boot 3.2 and later, spring.threads.virtual.enabled=true switches the supported executors, such as Tomcat's request threads and the default task executor, to virtual threads. Before enabling it, I check for synchronized blocks around blocking calls, which pin the carrier thread on Java 21 (JDK 24 removed most of this pinning), for ThreadLocal-heavy code that will now create a copy per task, and for connection pools, which become the real limit once there are thousands of concurrent threads. After enabling it, I load test and watch JFR events such as jdk.VirtualThreadPinned, pool wait times and latency before rolling out.
Why this question is asked
Virtual threads promise more throughput with the same simple blocking code, and in Spring Boot turning them on is one property. That simplicity is exactly why interviewers ask this question: the risk is not in the switch, it is in what the switch reveals about the code and its resources. In this answer, we will recap what changes when virtual threads replace a platform pool, look at what the property configures, go through the checks before enabling it with examples, and then the checks after.
1A Quick Recap: What Changes When Virtual Threads Replace a Pool
A Spring Boot service on Tomcat handles each request on a platform thread from a pool, 200 threads by default. When all 200 are busy, for example waiting on slow downstream calls, new requests queue. That pool size is an accidental limit on concurrency: it protects the database and downstream services because no more than 200 requests can be in flight.
Virtual threads are cheap JVM-managed threads that unmount from their carrier OS thread while they block. With them, Tomcat creates one virtual thread per request and the 200-thread limit disappears. The service can now have thousands of requests in flight, waiting on I/O. That is the benefit, and it is also why every downstream resource suddenly sees much more concurrency.
2What the Property Configures
Spring Boot 3.2 added one property for this. It requires Java 21 or later.
Notice the last line. Virtual threads are always daemon threads, so an application that has no non-daemon threads, such as a scheduler-only app, could exit right after startup; spring.main.keep-alive prevents that. The exact list of components covered grows with each Boot release, so check your version. Executors we created ourselves are not changed; we switch them explicitly, for example with Executors.newVirtualThreadPerTaskExecutor().
3Before Enabling: Pinning on Java 21
On Java 21, a virtual thread that blocks while inside a synchronized block or method cannot unmount; it stays pinned to its carrier. The JVM has only as many carriers as CPU cores by default, so a few pinned threads can stall all the others. Common sources are older JDBC drivers, connection pools and caches that use synchronized around I/O.
Notice that the second version keeps the same mutual exclusion. JDK 24, through JEP 491, made synchronized itself unmount in most cases, so on 24 and later this rewrite is rarely needed. Pinning can still happen during native calls and a few other cases. On 21, we search our own code and check that libraries such as the JDBC driver and pool are versions that avoid synchronized around I/O.
4Before Enabling: Connection Pools and ThreadLocals
With the 200-thread limit gone, the connection pool becomes the limit. HikariCP's default pool has 10 connections. If 2,000 virtual threads each need a connection, 1,990 wait, and if they wait longer than connectionTimeout, 30 seconds by default, they fail. We size the pool deliberately for what the database can handle, set timeouts we can live with, and sometimes add a Semaphore around a fragile downstream call to restore an explicit concurrency limit, since the thread pool no longer provides one.
ThreadLocal is the second check. Code that caches expensive objects in a ThreadLocal, such as a SimpleDateFormat, a buffer or a parser, relied on the pool reusing 200 threads, so there were only 200 copies. With a new virtual thread per task, every request creates its own copy and throws it away, which means more allocation and no caching benefit. We replace these with thread-safe shared objects, such as DateTimeFormatter, or proper pools. Small context values in ThreadLocals, like a request id, are fine.
- Java 21 or later, Boot 3.2 or laterSet
spring.threads.virtual.enabled - synchronized around blocking I/O?YesReplace with ReentrantLock or move to JDK 24+NoContinue
- Size connection pools deliberatelyAdd semaphores for fragile downstreams
- Remove ThreadLocal cachesUse shared thread-safe objects
- Load test with JFRWatch
jdk.VirtualThreadPinned, pool waits - Roll out graduallyCompare latency, errors, CPU, memory
6 steps in order. Play them, or step through them one at a time.
5After Enabling: Measure Before Rolling Out
We load test with production-like traffic and record with JFR, which has events for virtual threads. jdk.VirtualThreadPinned reports pinned threads with stack traces, so we can find the exact synchronized block. On Java 21 the system property -Djdk.tracePinnedThreads=full also prints stack traces, though later releases removed it. We also watch the connection pool's pending threads and wait time, downstream error rates, p99 latency, heap use and CPU.
Notice that the event shows the duration and the stack, so we can tell harmless short pins from real problems. If the numbers look good, we roll out to a few instances first and compare them with the platform-thread instances. And if a service is CPU-bound rather than waiting on I/O, virtual threads will not help, and we can leave it as it is.
6Follow-up questions
Do virtual threads make each request faster?
No. A single request takes the same time. The gain is throughput under concurrency: more requests can wait on I/O at once without needing more OS threads, so the service handles more load before queuing. If the service was never limited by its thread pool, the improvement is small.
What about @Transactional and security contexts that use ThreadLocal?
They keep working, because each request still runs on one thread from start to finish, now a virtual one. Spring's transaction and security contexts are small per-request values, which is the right use of ThreadLocal. The concern is only large cached objects.
Should we still use WebFlux?
For most request-response services that block on databases and HTTP calls, virtual threads give similar scalability with simpler code. WebFlux still makes sense for streaming, backpressure and services already built on reactive libraries.
7Conclusion
In this answer, we saw that spring.threads.virtual.enabled=true in Spring Boot 3.2 and later moves Tomcat, Jetty and the default task executor to virtual threads, which removes the thread pool as an accidental concurrency limit. Before enabling it, we look for synchronized around blocking calls, which pin carriers on Java 21 but mostly not since JDK 24, size connection pools and add explicit limits, and remove ThreadLocal caches. After enabling it, we load test with JFR events such as jdk.VirtualThreadPinned and roll out gradually while comparing latency, errors and resource use.
Open with
In Spring Boot 3.2 and later on Java 21, the switch itself is one property, spring.threads.virtual.enabled=true, which puts Tomcat or Jetty request handling, the default applicationTaskExecutor and scheduling onto virtual threads.
Then, if they want more
If the app has no other non-daemon threads I also set spring.main.keep-alive. Before enabling it I check three things.
First, pinning: on Java 21 a virtual thread that blocks inside synchronized cannot unmount and holds its carrier, and there are only as many carriers as cores, so I look for synchronized around I/O in our code and make sure the JDBC driver and pool are recent; on JDK 24 and later JEP 491 removed most of that pinning.
Second, resource limits: the 200-thread Tomcat pool used to cap concurrency, and without it thousands of requests can hit a Hikari pool of 10 connections and time out, so I size pools deliberately and add semaphores for fragile downstream services. Third, ThreadLocal caches, which now create a copy per request, so I replace them with shared thread-safe objects.
After enabling, I load test with production-like traffic and record JFR, looking at jdk.VirtualThreadPinned events with their stack traces, pool wait times, p99 latency, CPU and heap. Then I roll out to a few instances and compare. I would also remind the team that it helps I/O-bound services, not CPU-bound ones.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 24, Spring Boot 3.2
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your team plans to switch a Spring Boot 3 service from a platform thread pool to virtual...": https://scrivio-interview-library.netlify.app/java/java-versions/3c5ebe8e04/