Quick revision
The short answer
On Java 21 with Spring Boot 3.2 or later, spring.threads.virtual.enabled=true makes Tomcat and Jetty process each request on a virtual thread, and switches the auto-configured task executor and task scheduler to virtual threads as well. Blocking code can then serve many more concurrent requests without a large thread pool, but downstream limits such as connection pools still cap throughput. If only virtual threads are running, spring.main.keep-alive=true may be needed to keep the JVM alive.
What to remember
In this answer, we saw that spring.threads.virtual.enabled=true, on Java 21 with Boot 3.2 or later, moves Tomcat and Jetty request handling, the auto-configured task executor and scheduler, and several listeners to virtual threads. Blocking code then serves many concurrent requests without a large pool, while connection pools and other downstream limits still cap throughput, CPU work gains nothing, and a non-web application may need spring.main.keep-alive=true to keep the JVM running.
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.
On Java 21 with Spring Boot 3.2 or later, spring.threads.virtual.enabled=true makes Tomcat and Jetty process each request on a virtual thread, and switches the auto-configured task executor and task scheduler to virtual threads as well. Blocking code can then serve many more concurrent requests without a large thread pool, but downstream limits such as connection pools still cap throughput. If only virtual threads are running, spring.main.keep-alive=true may be needed to keep the JVM alive.
Why this question is asked
Virtual threads are the biggest change to Java concurrency in years, and Spring Boot exposes them through a single property. That makes it easy to switch on and easy to misunderstand what changed. Interviewers ask this to see whether we know exactly which parts of the application move to virtual threads, what improves, and what does not. In this answer, we will recap what a virtual thread is, list what the property changes in a Boot application, see how request handling behaves before and after, and then cover the limits and the keep-alive detail.
1A Quick Recap of Virtual Threads
A platform thread is a Java thread backed one-to-one by an operating system thread. It is expensive: each reserves a large stack and the OS schedules it, so a server can comfortably run a few hundred. A virtual thread, final since Java 21, is a thread scheduled by the JVM. Many virtual threads run on a small pool of platform threads called carriers. When a virtual thread blocks on I/O, such as a socket read or a JDBC call, the JVM unmounts it from its carrier and runs another one, then mounts it again when the data arrives.
So a blocked virtual thread costs a little heap memory, not an OS thread. We can have hundreds of thousands of them, and plain blocking code no longer wastes a scarce resource while it waits.
2What the Property Changes in Spring Boot
The property is read by several auto-configurations, each of which switches its own component to virtual threads.
| Component | Before | After |
|---|---|---|
| Tomcat or Jetty requests | Pool of 200 platform threads | A virtual thread per request |
applicationTaskExecutor (@Async) | ThreadPoolTaskExecutor | SimpleAsyncTaskExecutor, virtual |
Task scheduler (@Scheduled) | ThreadPoolTaskScheduler, 1 thread | SimpleAsyncTaskScheduler, virtual |
| Messaging listeners | Platform threads | Virtual threads (check version) |
| Our own Executors | Platform threads | Unchanged |
For the web server, Tomcat and Jetty run each request on a new virtual thread instead of a worker from their pool, so server.tomcat.threads.max no longer limits how many requests run at once. For background work, the auto-configured applicationTaskExecutor, used by @Async and Spring MVC's async request handling, becomes a SimpleAsyncTaskExecutor that starts a virtual thread per task, and the auto-configured scheduler, used by @Scheduled, becomes a SimpleAsyncTaskScheduler on virtual threads. Several messaging integrations, for example Kafka and RabbitMQ listener containers, also use virtual threads when the property is set (check your version for the exact list).
Notice what does not change: executors we create ourselves with new ThreadPoolExecutor or Executors.newFixedThreadPool stay on platform threads. The property only affects what Boot auto-configures.
3How Request Handling Behaves Before and After
Imagine an endpoint that calls a slow partner API taking 500 milliseconds, and 1,000 requests arriving at once. With the default pool of 200 platform threads, 200 requests run and 800 wait for a thread, so the last ones finish after about 2.5 seconds. With virtual threads, all 1,000 start at once, each blocks on the partner call, and all finish after about 500 milliseconds, as long as the partner can take 1,000 parallel calls.
This is the core benefit: blocking code can scale to many concurrent requests without a large thread pool and without rewriting it in a reactive style. The code is the same plain, readable code as before.
7 messages in order. Play them, or step through them one at a time.
A few carrier threads serve all 1,000 requests because waiting threads give their carrier back.
4What Still Limits Throughput
Virtual threads remove the limit on waiting threads, not the limits behind them. If each request needs a database connection and Hikari has 10, then only 10 requests use the database at a time, and the other 990 virtual threads wait for a connection. If the partner API accepts 100 parallel calls, the other 900 calls queue or fail at the partner. So throughput is capped by the smallest downstream limit, and removing the thread pool often reveals that limit for the first time.
Two more limits come from the JVM itself. CPU-bound work gains nothing, because virtual threads still need a carrier to compute. And on JDKs before 24, a virtual thread that blocks inside a synchronized block is pinned to its carrier, so it cannot unmount and the carrier is held; JDK 24 removed most of that pinning (JEP 491).
5Keeping the JVM Alive
Virtual threads are always daemon threads, and the JVM exits when only daemon threads remain. A web application is not affected, because the server keeps a non-daemon thread running. But an application with no web server, for example one that only runs @Scheduled jobs, can exit right after startup once the scheduler runs on virtual threads, because nothing non-daemon is left.
So spring.main.keep-alive is not needed for typical web services, but it is the first thing to check if a non-web application stops immediately after enabling virtual threads.
6Follow-up questions
Do we need Java 21 for this property?
Yes. Virtual threads are final from Java 21, and the property has no effect on older Java versions, where Boot keeps platform threads. On Java 21 to 23 it works, but pinning in synchronized blocks is more common than on Java 24 and later.
Should we still set server.tomcat.threads.max?
With virtual threads on, Tomcat no longer uses that pool for requests, so the property loses its meaning as a concurrency limit. If we want to limit concurrency, we do it explicitly, for example with a semaphore around a downstream call or a limit at the load balancer.
Are ThreadLocals safe with virtual threads?
They work, because each virtual thread has its own ThreadLocal values. But with a thread per request there is no pooling, so ThreadLocal caches that relied on reuse, such as a cached formatter per thread, are created again for every request and can cost a lot of memory with many threads.
7Conclusion
In this answer, we saw that spring.threads.virtual.enabled=true, on Java 21 with Boot 3.2 or later, moves Tomcat and Jetty request handling, the auto-configured task executor and scheduler, and several listeners to virtual threads. Blocking code then serves many concurrent requests without a large pool, while connection pools and other downstream limits still cap throughput, CPU work gains nothing, and a non-web application may need spring.main.keep-alive=true to keep the JVM running.
Open with
On Java 21 or later with Spring Boot 3.2 or later, that property switches the parts Boot auto-configures to virtual threads. The most visible change is the web server: Tomcat and Jetty run each request on a new virtual thread instead of a worker from a pool of 200, so threads.max stops being the concurrency limit.
Then, if they want more
The auto-configured applicationTaskExecutor, which @Async uses, becomes a SimpleAsyncTaskExecutor on virtual threads, and the scheduler behind @Scheduled uses virtual threads too, as do several listener containers. Executors we create ourselves are not changed.
The benefit is that blocking code can scale to many concurrent requests: when a virtual thread blocks on I/O, the JVM unmounts it and its carrier thread runs another, so a thousand requests waiting on a slow API cost little. But downstream limits still apply.
If Hikari has 10 connections, only 10 requests use the database at once and the rest wait, and CPU-bound work does not get faster. On JDKs before 24, synchronized blocks can pin a virtual thread to its carrier.
One more detail: virtual threads are daemon threads, so an application without a web server, say one that only runs scheduled jobs, can exit at startup, and spring.main.keep-alive=true keeps the JVM alive.
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
- Spring Boot reference
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 "What does spring.threads.virtual.enabled=true change in a Spring Boot 3.2+ application...": https://scrivio-interview-library.netlify.app/spring-boot/embedded-servers/b92af9ea82/