Quick revision
The short answer
We set spring.threads.virtual.enabled=true, on Spring Boot 3.2 or later running on Java 21 or later. Boot then makes embedded Tomcat and Jetty run each request on a new virtual thread, switches the auto-configured application task executor (used by @Async and similar features) and the task scheduler to virtual threads, and does the same for several message listener containers. It does not change connection pools or any other limit, and because virtual threads are daemon threads, apps with no other non-daemon thread may need spring.main.keep-alive=true.
What to remember
In this answer, we saw that spring.threads.virtual.enabled=true, on Spring Boot 3.2 or later with Java 21 or later, makes embedded Tomcat and Jetty run each request on a virtual thread, switches the auto-configured task executor and scheduler to virtual threads, and does the same for several message listener containers. It leaves connection pools and our own executors unchanged, so concurrency limits must become explicit, and because virtual threads are daemon threads, applications without a web server may need spring.main.keep-alive=true.
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.
We set spring.threads.virtual.enabled=true, on Spring Boot 3.2 or later running on Java 21 or later. Boot then makes embedded Tomcat and Jetty run each request on a new virtual thread, switches the auto-configured application task executor (used by @Async and similar features) and the task scheduler to virtual threads, and does the same for several message listener containers. It does not change connection pools or any other limit, and because virtual threads are daemon threads, apps with no other non-daemon thread may need spring.main.keep-alive=true.
Why this question is asked
Virtual threads are the biggest change to Java concurrency in years, and in Spring Boot turning them on is a single property. That is exactly why interviewers ask about it: a one-line change that alters how every request is executed deserves to be understood before it goes to production. In this answer, we will recap what a virtual thread is, turn the setting on, walk through what Boot changes when we do, and then look at what it leaves alone, including the keep-alive setting and the connection pool.
1A Quick Recap of Virtual Threads
A platform thread, the classic java.lang.Thread, is a thin wrapper around an operating system thread. OS threads are expensive: each reserves stack memory and the OS schedules them, so a service usually runs a few hundred of them in a pool. A virtual thread is a thread managed by the JVM. It runs on top of a small pool of platform threads, called carriers, and when it blocks on I/O such as a socket read, the JVM unmounts it from its carrier and lets another virtual thread use that carrier. Millions of virtual threads can exist at once.
That changes the usual design. With platform threads we share a fixed pool between tasks; with virtual threads we simply start a new one for each task, and blocking is cheap again.
2Turning It On
The switch arrived in Spring Boot 3.2. The application must also run on Java 21 or later, because that is where virtual threads became final; on an older JDK the property has no effect.
Notice the output of the check. With the setting on, the request runs on a VirtualThread, and the part after the @ shows which carrier thread from the JVM's ForkJoinPool it is mounted on at that moment. With the setting off, it runs on one of Tomcat's pooled platform threads, named http-nio-8080-exec-N.
3What the Setting Changes
The property is read by several auto-configurations, and each swaps a pooled platform-thread executor for one that starts a virtual thread per task. For the web server, Boot gives embedded Tomcat and Jetty an executor that runs each request on a new virtual thread instead of the usual pool of up to 200 threads. For @Async, Spring's task execution and anything else that uses the auto-configured applicationTaskExecutor, Boot provides a SimpleAsyncTaskExecutor that uses virtual threads instead of a ThreadPoolTaskExecutor. For @Scheduled, the auto-configured scheduler becomes a SimpleAsyncTaskScheduler that runs each task on a virtual thread.
Several messaging integrations follow the same property, such as the listener containers for RabbitMQ and Kafka and some Redis listener support. The exact list grows from release to release, so check the Spring Boot reference documentation for your version, under the section on virtual threads, before assuming a particular component is covered.
| Component | Disabled | Enabled |
|---|---|---|
| Tomcat or Jetty requests | Pooled platform threads (Tomcat: 200 max) | New virtual thread per request |
applicationTaskExecutor (@Async) | ThreadPoolTaskExecutor | SimpleAsyncTaskExecutor on virtual threads |
@Scheduled scheduler | ThreadPoolTaskScheduler | SimpleAsyncTaskScheduler on virtual threads |
| Some listener containers | Platform threads | Virtual threads (check your version) |
| HikariCP pool, HTTP client pools | Unchanged | Unchanged |
4What It Leaves Alone
The setting changes threads, not limits. The HikariCP connection pool still has 10 connections by default, HTTP client connection pools keep their sizes, and rate limits on downstream services stay where they are. Before, Tomcat's thread pool quietly capped how many requests could run at once, which also capped how many of them could wait for a database connection. With virtual threads that cap is gone, so a traffic spike now turns into a long queue at the connection pool, and possibly connection timeout errors. Plan explicit limits, such as a semaphore around a scarce resource, rather than relying on thread counts.
The setting also does not change our own executors. If we create Executors.newFixedThreadPool(50) somewhere, those tasks still run on 50 platform threads. And it cannot make blocking code inside synchronized blocks friendlier on JDK 21 to 23, where blocking while holding a monitor pins the virtual thread to its carrier; JDK 24 and later remove most of that pinning.
5The Daemon Thread Catch and spring.main.keep-alive
Virtual threads are always daemon threads, and the JVM exits when only daemon threads are left. In a web application, the server keeps a non-daemon thread alive, so nothing changes. But an application that only runs @Scheduled jobs used to stay alive because the scheduler's platform threads were non-daemon. With virtual threads enabled, those tasks run on daemon threads, so the JVM can exit right after startup.
So for scheduling-only or listener-only applications, we set spring.main.keep-alive=true together with the virtual threads property.
6Follow-up questions
Do I need to change my controllers or services?
Usually not. The point of virtual threads is that ordinary blocking code, such as JDBC calls and RestClient requests, keeps working and simply scales better. What we should review is code that relies on thread pools as limits, large objects cached in ThreadLocals, and long blocking calls inside synchronized blocks on JDKs before 24.
Does enabling virtual threads make requests faster?
Not a single request. It raises how many requests can wait for I/O at the same time without running out of threads. If the service was never short of threads, or if it is CPU-bound, we may see no difference at all, and if a downstream resource is the limit, we see more waiting there instead.
How can I tell whether virtual threads pin carriers?
Java Flight Recorder records a jdk.VirtualThreadPinned event when a virtual thread blocks while pinned for longer than a threshold. Recording a load test with JFR and looking for those events shows where it happens. On JDK 24 and later, synchronized no longer pins, so the remaining cases are mostly native calls.
7Conclusion
In this answer, we saw that spring.threads.virtual.enabled=true, on Spring Boot 3.2 or later with Java 21 or later, makes embedded Tomcat and Jetty run each request on a virtual thread, switches the auto-configured task executor and scheduler to virtual threads, and does the same for several message listener containers. It leaves connection pools and our own executors unchanged, so concurrency limits must become explicit, and because virtual threads are daemon threads, applications without a web server may need spring.main.keep-alive=true.
Open with
I set spring.threads.virtual.enabled=true. That needs Spring Boot 3.2 or later and the app has to run on Java 21 or later. What it changes is where work runs.
Then, if they want more
Embedded Tomcat and Jetty stop using their pool of platform threads, 200 by default for Tomcat, and run each request on a new virtual thread. The auto-configured application task executor, which @Async uses, becomes a SimpleAsyncTaskExecutor on virtual threads, and the scheduler for @Scheduled becomes a SimpleAsyncTaskScheduler on virtual threads.
Several listener containers, like Kafka and RabbitMQ, follow the same property; the exact list depends on the Boot version, so I check the reference docs. What it does not change is limits. The Hikari pool still has 10 connections, HTTP client pools are the same size, and my own fixed thread pools still use platform threads.
Since Tomcat's thread cap used to limit database concurrency too, I add explicit limits where a resource is scarce. One more catch: virtual threads are daemon threads, so an app with only scheduled jobs and no web server can exit right after startup. For those, I also set spring.main.keep-alive=true, which keeps a non-daemon thread alive.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Spring Boot 3.2, Java 24
- 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
- JEP 444, Virtual Threads
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 "How do you enable virtual threads in Spring Boot, and what does the setting change?": https://scrivio-interview-library.netlify.app/java/virtual-threads/53febdaac7/