Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

Your team plans to enable virtual threads with spring.threads.virtual.enabled=true on a Spring Boot 3.5 MVC service. How does that change how you tune thread pools and connection pools?

With spring.threads.virtual.enabled=true, Tomcat runs each request on a new virtual thread, so the request thread count no longer limits how many requests run at once. The limit moves to downstream resources: the HikariCP pool now protects the database on its own, and other dependencies may need semaphores or bulkheads, while timeouts matter more because unbounded concurrency can turn a slow dependency into a huge backlog. JDK 24 removed most pinning of carrier threads in synchronized blocks (JEP 491), but on JDK 21 we must check libraries for synchronized around I/O, and we load test before and after while watching memory, since many more requests hold their data at the same time.

Why this question is asked

Virtual threads are one of the biggest changes to Java concurrency in years, and Spring Boot makes them a one-line switch. That simplicity hides a shift in how we tune a service: the old dial, the size of the request thread pool, mostly disappears, and limits we never thought about become the only ones left. Interviewers ask this to see whether we understand where concurrency is now controlled and what can go wrong. In this answer, we will recap what virtual threads are and what the property changes, see why the connection pool becomes the main limit, add bulkheads and timeouts for other dependencies, look at pinning on different JDK versions, and plan the load test.

1A Quick Recap of Virtual Threads

A platform thread is a thin wrapper around an operating system thread. It is expensive: about a megabyte of reserved stack and a kernel scheduling entry, so a service can have hundreds or a few thousand, which is why Tomcat uses a pool of 200 by default. A virtual thread, final since JDK 21, is a thread managed by the JVM. It runs on a small pool of platform threads called carrier threads, and when it blocks on I/O, a lock from java.util.concurrent or a sleep, the JVM unmounts it from its carrier and lets another virtual thread run. Creating one costs about as much as creating a small object, so we can have hundreds of thousands, and we create one per task instead of pooling them.

In Spring Boot 3.2 and later, including 3.5, setting spring.threads.virtual.enabled=true on JDK 21 or newer makes embedded Tomcat run each request on a virtual thread, and also switches the auto-configured task executor for @Async and the scheduler to virtual threads.

YAML
# application.yml (Spring Boot 3.5, JDK 21+)
spring:
threads:
virtual:
enabled: true # Tomcat: one virtual thread per request
# server.tomcat.threads.max no longer limits concurrent requests
# server.tomcat.max-connections (default 8192) still limits open connections

2What Changes: the Request Thread Count Stops Being the Limit

With platform threads, the 200-thread pool was a limit we often relied on without noticing. At most 200 requests could be inside the application, so at most 200 could wait for database connections, call other services or hold request data in memory. Excess requests waited in Tomcat's accept queue.

With virtual threads, that limit is gone. Every accepted connection's request gets its own thread immediately, up to the number of connections Tomcat accepts. Under a burst, 3,000 requests can be inside the application at once. That is the point, since requests that mostly wait for I/O no longer need an expensive thread each, but it also means every resource behind the request now sees the full concurrency.

Step throughWhere concurrency is limited
  1. Tomcat connectionsmax-connections, still a limit
  2. Request threadsvirtual: effectively unlimited
  3. Bulkheads for dependenciessemaphores per downstream
  4. HikariCP poolprotects the database
  5. Database and downstream servicesfixed real capacity

5 layers, from the top down. Step through them one at a time.

With virtual threads, the layers below the request threads do the protecting.

3The Connection Pool Becomes the Gate for the Database

The HikariCP pool now stands alone between thousands of request threads and the database, and it does its job: it still allows only maximumPoolSize connections, so the database is protected. We do not raise the pool to match the new concurrency; the database's capacity has not changed.

What changes is the queue in front of the pool. Before, at most 200 threads could wait there; now thousands can. With the default connectionTimeout of 30 seconds, a burst can build a long queue of requests that all wait and then all fail. So we set connectionTimeout to a value that matches the service's latency target, a second or two, and we watch hikaricp.connections.pending, which will now show far larger numbers under load than it ever did.

4Bulkheads and Timeouts for Other Dependencies

Other dependencies have no pool in front of them unless we add one. An HTTP client's connection pool may limit connections, but a payment service that handles 50 concurrent calls well and slows down at 500 now receives whatever our traffic sends it. So we add bulkheads: a limit on concurrent calls per dependency, implemented with a Semaphore or Resilience4j's semaphore bulkhead. With virtual threads, waiting on a semaphore is cheap, so this is the natural tool. We do not limit virtual threads by pooling them; we limit access to the scarce resource.

Java
private final Semaphore paymentPermits = new Semaphore(50); // the payment service's comfortable limit
PaymentResult charge(Order order) throws InterruptedException {
if (!paymentPermits.tryAcquire(200, TimeUnit.MILLISECONDS)) {
throw new ServiceBusyException("payment"); // shed load: 503 instead of a backlog
}
try {
return paymentClient.charge(order); // client has its own 2 s timeout
} finally {
paymentPermits.release();
}
}

Timeouts matter more than before. If the payment service slows down from 100 ms to 5 seconds and there is no timeout, virtual threads keep accepting requests and each one waits, so thousands of requests pile up, each holding its memory, until the service runs out of heap. Every outgoing call needs a connect and read timeout, and the bulkhead's acquisition timeout keeps the backlog bounded.

5Pinning: JDK 21 Versus JDK 24 and Later

A virtual thread is pinned when it cannot unmount from its carrier while blocked, so it occupies a carrier thread, of which there are only about as many as CPU cores. On JDK 21 to 23, blocking inside a synchronized block or method pins the virtual thread. If a library does I/O inside synchronized, for example an older JDBC driver or a connection pool, a few dozen blocked requests can occupy every carrier and the whole application stalls although the CPU is idle.

JDK 24 changed this with JEP 491: synchronized no longer pins in the common cases, so virtual threads can block inside it and unmount normally. Some pinning remains, for example while running native code. So on JDK 21 we check our libraries for synchronized around I/O, prefer versions that use ReentrantLock, and detect pinning with JDK Flight Recorder's jdk.VirtualThreadPinned event; on JDK 24 or 25 the concern mostly disappears, which is a good reason to run virtual threads on a current JDK such as 25 LTS.

Tuning before and after virtual threads
ConcernPlatform threadsVirtual threads
Request concurrency limitserver.tomcat.threads.max (200)none in practice
Database protectionpool plus 200-thread capHikariCP pool alone
Other dependenciesimplicitly capped by threadssemaphores or bulkheads
connectionTimeout30 s default often toleratedshort, near the latency target
synchronized with I/Ofinepins on JDK 21-23; fixed in JDK 24+
Memory under burstbounded by 200 requestsbounded only by load: watch heap

6Load Testing Before and After

We do not enable virtual threads on trust. We run the same load test with the property off and on, at normal load and at bursts beyond it, and compare throughput, p99, errors, hikaricp.connections.pending, GC activity and heap usage. Memory deserves special attention: with 3,000 requests in flight instead of 200, all their request bodies, entities and response buffers live at once, and per-thread caches in ThreadLocal multiply with the number of threads. If heap grows dangerously, we cap concurrency at the edge, for example with a semaphore around request handling or Tomcat's max-connections, rather than going back to a thread pool.

7Follow-up questions

Should we put virtual threads in a pool to limit them?

No. Virtual threads are cheap to create and meant to be used once per task; pooling them adds complexity without benefit. To limit concurrency, we limit access to the resource that is scarce, with a semaphore, a bulkhead, a connection pool or a limit on accepted connections, which keeps the limit next to the thing it protects.

Does a service that is mostly CPU-bound benefit?

Little. Virtual threads help when threads spend most of their time waiting on I/O. A CPU-bound service is limited by cores, and running more threads than cores only adds switching. Such services can keep platform threads.

What about @Async and scheduled tasks?

With the property on, Spring Boot's auto-configured executor for @Async creates a virtual thread per task instead of using a bounded pool with a queue, so concurrency there is unbounded too. If those tasks call limited resources, we set the executor's concurrency limit or use semaphores, the same way as for requests.

8Conclusion

In this answer, we saw that spring.threads.virtual.enabled=true removes the request thread pool as a concurrency limit, so protection moves to downstream resources: HikariCP alone guards the database, with a shorter connectionTimeout, and semaphores or bulkheads guard other dependencies, backed by timeouts so slow dependencies cannot build huge backlogs. Pinning in synchronized blocks matters on JDK 21 but was largely removed in JDK 24 by JEP 491, and load tests before and after, with close attention to memory, decide whether the switch is safe.

What to say in the interviewAbout 100 seconds aloud

Open with

Turning on spring.threads.virtual.enabled makes Tomcat run every request on its own virtual thread, so server.tomcat.threads.max no longer limits concurrency. That is the main change in how I tune.

Then, if they want more

Before, the 200-thread pool quietly capped everything behind it, how many requests waited for connections, called other services or held memory. With virtual threads, a burst of thousands of requests all get into the application, so the limits must move to the resources that are really scarce. The HikariCP pool now protects the database on its own.

I keep it sized to the database's capacity, not to the request count, but I shorten connectionTimeout to something near the latency target, because thousands of threads can queue in front of it instead of 200.

For other dependencies I add bulkheads, a semaphore or a Resilience4j semaphore bulkhead per downstream, so a payment service that is comfortable at 50 concurrent calls never sees 2,000. Timeouts on every outgoing call become essential, because without them a slow dependency turns into a huge backlog of waiting virtual threads, each holding memory.

On pinning: on JDK 21, a virtual thread blocked inside synchronized pins its carrier, so I would check libraries for synchronized around I/O and watch the JFR pinned event. JDK 24's JEP 491 removed most of that, so I prefer running on 25.

Finally, I would load test with the property off and on, including bursts, and watch throughput, p99, pending connections and especially heap, since far more requests hold their data at once.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Java 24, Spring Boot 3.2, Spring Boot 3.5
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
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 enable virtual threads with spring.threads.virtual.enabled=true on a...": https://scrivio-interview-library.netlify.app/spring-boot/service-performance/ee5a5d21d5/