Home / Insights / Architecture and Modernization

Architecture and Modernization

Java Virtual Threads in Practice: What They Change for High-Concurrency Services

Virtual threads let ordinary blocking Java code handle far more concurrent work without reactive rewrites. They are not a free speed-up, though. This guide explains where they pay off, what breaks, and how to adopt them safely in production services.

TopicsArchitecture and ModernizationWeb and SaaS Development

Key takeaways

  • Virtual threads improve throughput for services that spend most of their time waiting on I/O; they do not make individual requests faster or help CPU-bound work.
  • The bottleneck usually moves from threads to downstream resources such as database connections, rate-limited APIs and memory, so concurrency limits must be made explicit.
  • JDK 24 removed most pinning caused by synchronized blocks (JEP 491), which makes JDK 25 LTS a stronger target than JDK 21 for heavy virtual-thread workloads.
  • In Spring Boot 3.2 and later, a single property switches the main executors to virtual threads, but libraries, thread-local caches and connection pools still need review.
  • Adopt them like any other runtime change: baseline, load test, enable behind configuration, watch pinning and pool saturation, then expand.

For years, Java teams that needed tens of thousands of concurrent requests had two choices: buy more memory and run very large thread pools, or rewrite code in a reactive, callback-based style that is harder to read, debug and hire for. Virtual threads, final since JDK 21, offer a third option: keep simple blocking code and let the runtime multiplex many lightweight threads onto a small number of operating system threads.

This article is for CTOs, architects and engineering leads who run Java services, typically Spring Boot APIs, integration services and back-office platforms, and want to know whether virtual threads are worth adopting, what they change in system design and how to roll them out without surprises. It reflects the questions we work through when our Java developers tune Spring Boot services and upgrade legacy Java versions for clients.

What do virtual threads actually change?

A platform thread is a thin wrapper around an operating system thread. Each one reserves stack memory and costs the OS scheduling work, so servers cap them in pools of a few hundred. When a request blocks on a database call or an HTTP call, its thread sits idle but still occupies a pool slot.

A virtual thread is a java.lang.Thread managed by the JVM. According to Oracle’s Java 21 virtual threads guide, when a virtual thread blocks on I/O the runtime unmounts it from its carrier platform thread, which can then run another virtual thread. Blocking becomes cheap, so the old thread-per-request style scales again.

Scale, not speed

Oracle is explicit that virtual threads provide higher throughput, not lower latency: they do not run code faster. Its rule of thumb is that an application that never has around 10,000 or more virtual threads at once is unlikely to benefit. That sets the right expectation for decision-makers: virtual threads help a service do more waiting in parallel, not compute faster.

WorkloadEffect of virtual threadsRecommendation
REST APIs calling databases and other servicesLarge gain in concurrent capacity if threads were the limitStrong candidate
Integration and fan-out services (many outbound HTTP calls)Simpler code than CompletableFuture chains; high concurrencyStrong candidate
Message consumers with blocking handlersUseful where handlers wait on I/OGood candidate; respect broker and partition limits
CPU-heavy batch, image or numerical processingNo gain; may add overheadKeep platform thread pools sized to cores
Already-reactive WebFlux services working wellLittle to gain from a rewriteLeave alone unless maintainability is the issue

Where does the bottleneck move?

The most common production surprise is not a virtual thread bug. It is that removing the thread limit exposes the next limit. A Tomcat pool of 200 threads was quietly acting as a concurrency throttle. Remove it, and 5,000 requests can arrive at a database pool of 30 connections at once.

Limits you now need to manage explicitly

  • Database connections. The connection pool becomes the real cap. Oracle notes that database connection pools already behave like semaphores, so do not add another limit on top of them; instead set sensible acquisition timeouts so requests fail fast rather than queue indefinitely.
  • Rate-limited downstream APIs. Payment gateways, ERP systems and partner APIs have quotas. Oracle recommends using a Semaphore to limit concurrency to a specific resource rather than a fixed thread pool.
  • Memory. Each virtual thread is small, but each request still allocates objects, buffers and response bodies. Tens of thousands of in-flight requests can push heap usage up sharply.
  • Back-pressure at the edge. Without a thread pool to fill up, overload shows up later and less visibly. Add admission control, timeouts and load shedding at the gateway or application edge.

For example, an illustrative order-tracking API that spends 90% of each request waiting on two downstream calls might sustain far more concurrent users after the switch, until the downstream carrier API starts returning rate-limit errors. The fix there is a semaphore and a retry policy, not more threads.

What are the technical pitfalls, and has JDK 24 fixed them?

Pinning

A virtual thread is pinned when it cannot unmount from its carrier during a blocking operation. In JDK 21, Oracle’s guide lists two causes: running inside a synchronized block or method, and running native code or foreign functions. Frequent, long-lived pinning can starve the small pool of carrier threads and erase the benefit. JDK 21’s guidance was to replace hot synchronized blocks that do I/O with ReentrantLock.

JEP 491 changes this. Virtual threads can now unmount while inside synchronized code, while waiting to acquire a monitor and in Object.wait(). Pinning remains when native code calls back into Java code that blocks, and the jdk.VirtualThreadPinned JFR event is kept for those cases. The JDK 24 project page lists JEP 491 in the release that reached general availability on 18 March 2025. In practice, that means JDK 24 or later removes the largest source of pinning in older libraries and JDBC drivers.

Thread-local caches

Many libraries cache expensive objects in ThreadLocal variables on the assumption that threads are pooled and reused. Virtual threads are created per task and never reused, so each task builds its own copy. Oracle’s guidance is to keep thread-locals for per-request context, not for caching expensive objects, and to replace patterns such as cached SimpleDateFormat with immutable shared objects.

Pooling virtual threads

Putting virtual threads in a fixed pool defeats the purpose. Oracle advises using Executors.newVirtualThreadPerTaskExecutor() and treating each virtual thread as a task, not a resource. Converting n platform threads into n virtual threads achieves little.

Mixing styles

Oracle also advises against mixing blocking code with asynchronous frameworks. A codebase half in CompletableFuture chains and half in blocking calls on virtual threads is harder to reason about than either style alone.

Which JDK and framework versions should you target?

Version choice matters more than usual because the pinning fix landed after JDK 21.

OptionVirtual threads statusMain consideration
JDK 21 LTSFinal (JEP 444); synchronized blocks pinWorks well for code using java.util.concurrent locks; audit hot synchronized I/O paths and drivers
JDK 24 (non-LTS)Includes JEP 491; synchronized no longer pinsShort support window; good for validation, less so for long-lived production
JDK 25 LTSIncludes JEP 491; GA scheduled for 16 September 2025Best target for new virtual-thread adoption once your libraries and vendors support it

The JDK 25 project page also shows related concurrency work continuing: structured concurrency (JEP 505) is in its fifth preview, and scoped values (JEP 506), a safer alternative to thread-locals for passing context, were proposed for finalisation in that release. Treat preview features as experiments, not production dependencies.

Spring Boot

The Spring Boot reference documentation shows that on Java 21 or later, setting spring.threads.virtual.enabled=true switches the auto-configured task executor and scheduler to virtual-thread implementations. Those executors are used by @EnableAsync, asynchronous Spring MVC request handling, blocking execution in WebFlux, WebSocket channels and bootstrap executors, unless you define your own. The documentation also notes that the virtual-thread scheduler ignores pooling properties, so any concurrency limits you relied on through pool sizes disappear.

If you are still on Java 17 or Spring Boot 2, virtual threads are a reason to plan the upgrade, not a reason to rush it. Our article on upgrading to Java 21 and Spring Boot 3 without a big bang covers that path.

How should you decide whether to adopt them?

Ask four questions before committing engineering time:

  1. Is the service I/O-bound? Profile a representative period. If most request time is spent waiting on databases, caches or other services, virtual threads are relevant. If CPU is saturated, they are not.
  2. Is the thread pool actually the constraint? Look for request queuing while CPU is low and threads are all busy waiting. If the database or a downstream API is already saturated, virtual threads will not help.
  3. Is the alternative a reactive rewrite? If you were considering moving to a reactive stack mainly for concurrency, virtual threads usually achieve similar capacity with far less change to code and skills.
  4. Are your dependencies ready? Check JDBC drivers, HTTP clients, caching libraries and observability agents for known virtual-thread issues and supported versions.

For example, a mid-sized logistics platform running a dozen Spring Boot services might select its two integration-heavy services as first candidates, leave its CPU-bound route optimisation service on platform threads and postpone its reactive notifications service indefinitely.

How do you roll them out safely?

  1. Baseline. Record throughput, p95 and p99 latency, error rates, heap usage and connection pool metrics under a realistic load test before any change.
  2. Upgrade the runtime first. Move to a supported JDK (preferably one with JEP 491) and current framework versions as a separate change, so you can isolate effects.
  3. Audit the code. Search for ThreadLocal caches, fixed thread pools used as throttles, and long synchronized sections around I/O if you remain on JDK 21.
  4. Make limits explicit. Set connection pool sizes and timeouts deliberately, add semaphores for rate-limited dependencies, and add admission control at the edge.
  5. Enable behind configuration. In Spring Boot, the single property makes it easy to enable per environment and per service, and to roll back.
  6. Load test again and compare. Look for higher throughput at similar latency, and check that the bottleneck has moved where you expected.
  7. Watch production signals. Monitor jdk.VirtualThreadPinned and jdk.VirtualThreadSubmitFailed JFR events, connection acquisition times and heap. Oracle notes that jcmd thread dumps can include virtual threads in text or JSON format.

Distributed tracing also needs checking: some context propagation relies on thread-locals. Our guide to observability with OpenTelemetry covers tracing setup that survives these changes.

What are the costs and risks?

RiskSymptomMitigation
Downstream overloadDatabase or partner API errors spike after enablingExplicit connection limits, semaphores, timeouts, circuit breakers
Carrier starvation from pinningThroughput falls under load; pinned events in JFRJDK 24+ or ReentrantLock in hot paths; update native-backed libraries
Memory growthHeap rises with in-flight requests; GC pausesAdmission control, streaming large payloads, heap sizing tests
Library incompatibilityUnexpected blocking or leaks in older drivers or agentsUpgrade dependencies first; test with production-like agents
Lost back-pressureOverload appears as slow downstream failures rather than queuingRate limiting at the gateway; clear timeout budgets

The direct engineering cost is often modest, especially on Spring Boot: the effort sits in dependency upgrades, load testing and observability rather than code rewrites. The bigger cost is in operational risk if the change is made without a baseline. Treat it as a runtime migration with a test plan, not a configuration tweak.

Skills matter too. Virtual threads reduce the need for reactive expertise, but teams still need engineers who understand JVM profiling, connection pools and concurrency limits, which is the profile we describe in hiring Java developers for enterprise systems.

Checklist before enabling virtual threads in production

  • The service is demonstrably I/O-bound and thread pool saturation is a real constraint.
  • You run a supported JDK, preferably 24 or later, or have audited synchronized I/O paths on JDK 21.
  • Spring Boot, JDBC drivers, HTTP clients and agents are on versions tested with virtual threads.
  • ThreadLocal caches and fixed pools used as throttles have been found and replaced.
  • Connection pools, semaphores and timeouts define concurrency limits explicitly.
  • A baseline load test exists, and the post-change test shows the expected improvement.
  • JFR pinning and submit-failure events, heap and pool metrics are on a dashboard.
  • The switch can be turned off by configuration without a redeploy of code.

Frequently asked questions

Will virtual threads make our API faster?

Not per request. Oracle describes virtual threads as providing scale rather than speed. They let a service handle more concurrent requests that are waiting on I/O, which can reduce queuing under load, but individual request latency is set by your code and dependencies.

Should we replace our reactive WebFlux code with virtual threads?

Only if the reactive style is causing real maintainability or hiring problems. A working reactive service does not gain capacity from a rewrite. For new I/O-heavy services, blocking code on virtual threads is often simpler to build and debug.

Is JDK 21 good enough, or do we need JDK 25?

JDK 21 supports virtual threads fully, but synchronized blocks pin carrier threads there. JDK 24 and later remove most of that pinning through JEP 491, so for heavy adoption JDK 25 LTS is the better long-term target, subject to your libraries and vendor support.

How much effort does adoption take?

For a Spring Boot service already on Java 21 and Boot 3.2 or later, enabling is a configuration change. The real effort is in auditing dependencies, making concurrency limits explicit, and load testing. Plan it as a small project per service rather than a one-line change.

Do virtual threads reduce cloud costs?

They can, if thread-related memory or instance counts were the constraint, but there is no guaranteed saving. Measure throughput per instance before and after under realistic load, and remember downstream services may need capacity changes too.

Sources and methodology

Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.

  1. Oracle: Java SE 21 Core Libraries, Virtual Threads — accessed 9 November 2026. Scale not speed, the 10,000-thread rule of thumb, no pooling, semaphores for limits, thread-local caveats, pinning causes and JFR/jcmd observability.
  2. OpenJDK: JEP 491, Synchronize Virtual Threads without Pinning — accessed 9 November 2026. Unmounting inside synchronized and Object.wait(), remaining native-code pinning cases and the retained jdk.VirtualThreadPinned event.
  3. OpenJDK: JDK 24 project page — accessed 9 November 2026. JDK 24 general availability on 18 March 2025 with JEP 491 in its feature list.
  4. OpenJDK: JDK 25 project page — accessed 9 November 2026. JDK 25 GA schedule (16 September 2025), structured concurrency fifth preview and scoped values proposed for finalisation.
  5. Spring Boot Reference: Task Execution and Scheduling — accessed 9 November 2026. spring.threads.virtual.enabled on Java 21+, components using the virtual-thread executor and the scheduler ignoring pooling properties.

Are your Java services ready to benefit from virtual threads?

We can profile your Spring Boot services, plan the JDK upgrade and run the load tests that show whether virtual threads will pay off.