Virtual Threads in Quarkus, Jakarta EE, Helidon and Micronaut
How the other major Java frameworks adopt virtual threads: Quarkus's @RunOnVirtualThread on an event-loop core, Micronaut's BLOCKING executor, Helidon 4's virtual-thread web server, and Jakarta Concurrency 3.1's virtual managed executors. Plus a demo of why the annotation matters.
kvi5hnuCode Sprout team member8 min readOn this page
Spring Boot adopted virtual threads with one global switch (article 48). The other major frameworks made different choices, and those choices follow from their architecture. Frameworks built on an event loop (Quarkus on Vert.x, Micronaut on Netty) let you move individual methods onto virtual threads. Helidon 4 rebuilt its web server around virtual threads, so there's nothing to switch on. Jakarta EE lets you declare a container-managed executor as virtual.

Why event-loop frameworks opt in per method
In Quarkus and Micronaut, a request first arrives on an event-loop thread (article 44). Non-blocking code can run right there. Blocking code must not, because it would stall every connection on that loop. So the framework needs to know, for each endpoint, where to run it. An annotation is the natural place to say so.
This program models that decision with a single event-loop thread and an annotation of its own. Ten slow requests are followed by one fast request, first with the slow endpoint annotated, then with the annotation forgotten:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Solution {
/** Our own marker, in the spirit of Quarkus's annotation of the same name. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface RunOnVirtualThread {}
static final Set<String> threadsUsed = ConcurrentHashMap.newKeySet();
/** The application's endpoints. */
public static class Endpoints {
public String cachedQuote(String route) { // fast, non-blocking: fine on the loop
threadsUsed.add("cachedQuote on " + kind());
return route + " " + (100 + route.chars().sum() % 400);
}
@RunOnVirtualThread
public String liveQuote(String route) throws InterruptedException {
threadsUsed.add("liveQuote on " + kind());
Thread.sleep(200); // blocking call to a slow partner
return route + " " + (100 + route.chars().sum() % 400);
}
public String liveQuoteForgotAnnotation(String route) throws InterruptedException {
threadsUsed.add("liveQuoteForgotAnnotation on " + kind());
Thread.sleep(200); // the same blocking call, on the loop
return route + " " + (100 + route.chars().sum() % 400);
}
}
static String kind() {
return Thread.currentThread().isVirtual() ? "a virtual thread" : Thread.currentThread().getName();
}
/** A tiny framework: one event-loop thread dispatches requests, and offloads annotated methods. */
static class MiniFramework implements AutoCloseable {
private final ExecutorService eventLoop = Executors.newSingleThreadExecutor(r -> new Thread(r, "event-loop"));
private final Object endpoints;
MiniFramework(Object endpoints) { this.endpoints = endpoints; }
CompletableFuture<String> request(String endpoint, String arg) {
CompletableFuture<String> reply = new CompletableFuture<>();
eventLoop.execute(() -> { // every request arrives on the loop
try {
Method m = endpoints.getClass().getMethod(endpoint, String.class);
if (m.isAnnotationPresent(RunOnVirtualThread.class)) {
Thread.startVirtualThread(() -> invoke(m, arg, reply)); // offload, loop stays free
} else {
invoke(m, arg, reply); // runs on the loop itself
}
} catch (NoSuchMethodException e) {
reply.completeExceptionally(e);
}
});
return reply;
}
private void invoke(Method m, String arg, CompletableFuture<String> reply) {
try {
reply.complete((String) m.invoke(endpoints, arg));
} catch (InvocationTargetException e) {
reply.completeExceptionally(e.getCause());
} catch (IllegalAccessException e) {
reply.completeExceptionally(e);
}
}
@Override public void close() { eventLoop.close(); }
}
static void scenario(String label, String slowEndpoint) {
threadsUsed.clear();
try (MiniFramework app = new MiniFramework(new Endpoints())) {
long start = System.nanoTime();
List<CompletableFuture<String>> slow = new ArrayList<>();
for (int i = 0; i < 10; i++) slow.add(app.request(slowEndpoint, "LIS-OSL"));
String fast = app.request("cachedQuote", "OSL-TOS").join(); // sent after the 10 slow ones
long fastMs = (System.nanoTime() - start) / 1_000_000;
CompletableFuture.allOf(slow.toArray(CompletableFuture[]::new)).join();
long allMs = (System.nanoTime() - start) / 1_000_000;
System.out.println(label);
System.out.println(" 10 slow requests, then 1 fast one: fast reply \"" + fast + "\" after "
+ (fastMs < 100 ? "under 100 ms" : fastMs > 1_500 ? "over 1.5 s" : fastMs + " ms")
+ "; all done after " + (allMs < 600 ? "under 0.6 s" : allMs > 1_500 ? "over 1.5 s" : allMs + " ms"));
System.out.println(" threads used: " + new TreeSet<>(threadsUsed));
}
}
public static void main(String[] args) {
try (MiniFramework warmUp = new MiniFramework(new Endpoints())) { // load classes, start the scheduler
warmUp.request("liveQuote", "LIS-OSL").join();
warmUp.request("cachedQuote", "LIS-OSL").join();
}
scenario("1. blocking endpoint annotated @RunOnVirtualThread:", "liveQuote");
scenario("2. the same endpoint without the annotation:", "liveQuoteForgotAnnotation");
}
}
Output:
1. blocking endpoint annotated @RunOnVirtualThread:
10 slow requests, then 1 fast one: fast reply "OSL-TOS 229" after under 100 ms; all done after under 0.6 s
threads used: [cachedQuote on event-loop, liveQuote on a virtual thread]
2. the same endpoint without the annotation:
10 slow requests, then 1 fast one: fast reply "OSL-TOS 229" after over 1.5 s; all done after over 1.5 s
threads used: [cachedQuote on event-loop, liveQuoteForgotAnnotation on event-loop]
- Annotated, each slow request was handed to its own virtual thread, and the loop went straight back to dispatching. The fast request, sent last, was answered at once, and all ten slow requests finished together after about 200 ms.
- Without the annotation, the same blocking code ran on the loop itself. The ten requests ran one after another for 2 seconds, and the fast request waited behind all of them. In a real server, that would also include health checks and every other connection on that loop.
The annotation never makes code faster. It decides which thread pays for the waiting. Real frameworks add a lot around this (context propagation, error mapping, metrics), but the core decision is this if.
Quarkus
Quarkus runs on Vert.x. In Quarkus REST, an endpoint that returns a reactive type like Uni runs on the event loop, and one that returns a plain type runs on a worker thread pool. @RunOnVirtualThread, experimental since Quarkus 2.10 and fully supported since Quarkus 3 on Java 21, runs a blocking endpoint on a new virtual thread instead:
import io.smallrye.common.annotation.RunOnVirtualThread;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;
import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/quote")
public class QuoteResource {
@Inject
@RestClient
FareClient fares; // a declarative REST client with a blocking signature
@GET
@RunOnVirtualThread
public String quote(@QueryParam("route") String route) {
int fare = fares.fare(route); // blocks this virtual thread, not a worker or the event loop
return route + " " + fare;
}
}
Details from the Quarkus virtual-threads guide:
- The annotation applies to blocking endpoints only: plain return types, or methods marked
@Blocking. Methods returningUnistay on the event loop. It can also go on the class, and it's supported for reactive messaging (@Incoming), gRPC and scheduled methods. - A reactive client can be used from a virtual thread by waiting for its result:
uni.await().atMost(Duration.ofSeconds(2)). That blocks only the virtual thread. - Virtual threads are named
quarkus-virtual-thread-Nby default (quarkus.virtual-threads.name-prefix). - The guide's warnings match this course: pinning by
synchronizedon Java 21 to 23 (article 13), monopolization of carriers by CPU-bound code (article 23), and libraries that pool expensive objects inThreadLocal, such as Jackson and Netty, which can then allocate one per virtual thread (article 15). - For tests, the
junit-virtual-threadsextension provides@ShouldNotPin, which fails a test that pins a carrier, using JFR events on any Java version from 21. Themicrometer-java21binder exports pinning and failed-start metrics.
Micronaut
Micronaut's HTTP server runs on Netty, and by default controllers run on the event loop. Since Micronaut 4.0, the executor named BLOCKING uses virtual threads when the JDK supports them, falling back to the IO pool otherwise. Blocking controllers opt in per method:
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.QueryValue;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
@Controller("/quote")
public class QuoteController {
private final FareRepository fares; // a JDBC-backed repository
QuoteController(FareRepository fares) {
this.fares = fares;
}
@Get
@ExecuteOn(TaskExecutors.BLOCKING) // a virtual thread when the JDK supports them
String quote(@QueryValue String route) {
return route + " " + fares.findFare(route);
}
}
Alternatively, micronaut.server.thread-selection=blocking runs every controller on a virtual thread. Micronaut 4.9 also added an experimental "loom carrier" mode, which runs virtual threads directly on the Netty event-loop threads instead of the JDK's ForkJoinPool, aiming for reactive-level performance. It relies on internal JDK APIs (--add-opens java.base/java.lang=ALL-UNNAMED) and is explicitly a prototype. Micronaut 5.0 (May 2026) raised the baseline to Java 25.
Helidon 4
Helidon took the opposite route. Helidon 4 (October 2023) replaced its Netty-based reactive web server with a new one written for virtual threads, developed as Project Níma. It runs every HTTP/1.1 request on its own virtual thread, and the SE API is plain blocking code:
import io.helidon.webserver.WebServer;
public class QuoteServer {
public static void main(String[] args) {
WebServer.builder()
.port(8080)
.routing(routing -> routing.get("/quote", (req, res) -> {
String route = req.query().get("route");
res.send(route + " " + FareService.fare(route)); // blocking is fine: this is a virtual thread
}))
.build()
.start();
}
}
There's no annotation and no offloading, because there's no event loop to protect. Helidon 4 requires Java 21, and its documentation recommends Java 25. Helidon 4.4 was released in April 2026.
Jakarta EE: Concurrency 3.1
Jakarta EE applications don't create threads themselves. They use container-managed executors, which propagate security, naming and transaction context to tasks. Jakarta Concurrency 3.1, part of Jakarta EE 11 (released in June 2025), added a virtual attribute to @ManagedExecutorDefinition, @ManagedScheduledExecutorDefinition and @ManagedThreadFactoryDefinition:
import jakarta.enterprise.concurrent.Asynchronous;
import jakarta.enterprise.concurrent.ManagedExecutorDefinition;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.concurrent.CompletableFuture;
@ManagedExecutorDefinition(
name = "java:module/concurrent/quotes",
virtual = true, // request virtual threads
maxAsync = 50) // at most 50 tasks of this executor run at once
@ApplicationScoped
public class QuoteService {
@Asynchronous(executor = "java:module/concurrent/quotes")
public CompletableFuture<String> quote(String route) {
String fare = PartnerApi.fare(route); // blocking call on a virtual thread
return Asynchronous.Result.complete(route + " " + fare);
}
}
Two details from the specification:
virtual = trueis a request, not a guarantee. The executor creates virtual threads "if it is capable of doing so" and if vendor configuration doesn't restrict them. On Java 17, which Jakarta EE 11 still supports, platform threads are used instead. Also, tasks that run inline, such as a completion-stage action triggered byjoin(), run on whatever thread is already there.maxAsynclimits how many of the executor's tasks run at the same time. With virtual threads, it's a convenient way to keep the implicit limit that a thread pool used to give you (article 48).
Runtime support arrived over 2024 to 2026. Open Liberty offered the concurrent-3.1 feature first, and GlassFish 8.0, a Jakarta EE 11 compatible implementation that requires Java 21, followed in early 2026. Check your server's documentation for vendor-specific settings, such as limits on virtual threads.
What's current
- Quarkus 3.x:
@RunOnVirtualThreadfor REST, messaging, gRPC and scheduled methods, plusjunit-virtual-threadsand Micrometer's virtual-thread metrics. The guide still documents-Djdk.tracePinnedThreadsonly for Java 21 to 23, since it was removed in Java 24. - Micronaut: 4.x uses virtual threads for the
BLOCKINGexecutor. 4.9 added the experimental loom carrier mode. 5.0 (May 2026) requires Java 25. - Helidon 4: a virtual-thread web server since 4.0 (October 2023). 4.4 was released in April 2026.
- Jakarta EE 11 (June 2025): Concurrency 3.1 with
virtual = true, implemented by GlassFish 8, Open Liberty and others.
Common questions
Is @RunOnVirtualThread faster than Quarkus's worker pool?
Not per request. It removes the worker pool's size limit, so many more blocking requests can wait at the same time. For CPU-heavy endpoints, the worker pool or the event loop with non-blocking code is still the better fit.
Can I use Mutiny or reactive clients from a virtual thread?
Yes. Call await() on the Uni with a timeout. It blocks the virtual thread, which is cheap, and the framework's event loop stays free.
Why doesn't Helidon need an annotation? Its web server doesn't run handlers on an event loop: every request already has its own virtual thread, so there's nothing to protect from blocking.
Do Jakarta EE servers run servlets on virtual threads? Not because of Concurrency 3.1, which covers managed executors, schedulers and thread factories. Some servers offer their own settings to run request handling on virtual threads. Those are vendor features, so check the server's documentation.
Summary
- Event-loop frameworks opt in per method: Quarkus with
@RunOnVirtualThread, and Micronaut with@ExecuteOn(TaskExecutors.BLOCKING)orthread-selection=blocking. Forgetting the annotation on blocking code stalls the event loop, as the demo showed. - Helidon 4 is built on virtual threads: one per request, blocking APIs, nothing to configure.
- Jakarta Concurrency 3.1 (Jakarta EE 11) adds
virtual = trueto managed executors, schedulers and thread factories. It's a request, and platform threads are used where virtual threads aren't available.maxAsyncbounds concurrency. - In every framework, the rules from earlier parts still apply: bound shared resources, avoid pinning on Java 21 to 23, keep CPU-bound work off virtual threads, and watch thread-local caches.
Practice questions
A Quarkus endpoint returns String, calls a JDBC repository, and is annotated @RunOnVirtualThread. A colleague changes its return type to Uni<String> but keeps the JDBC call. What happens?
Answer
A method returning Uni is treated as non-blocking and runs on the event loop, so @RunOnVirtualThread no longer applies. The JDBC call now blocks the event loop, and Vert.x will log blocked-thread warnings. Either keep the plain return type with the annotation, or use a reactive data client and stay non-blocking.
In the demo, why did the fast request take over 1.5 seconds in the second scenario, although its own code takes no time at all?
Answer
All requests were dispatched by one event-loop thread, in order. Without the annotation, each slow request blocked that thread for 200 ms, and the fast request, which arrived last, could only start after all ten were finished. It's head-of-line blocking: the delay comes from the shared loop, not from the request.
A Jakarta EE 11 application declares @ManagedExecutorDefinition(virtual = true) and runs on Java 17. Does it fail to deploy?
Answer
No. virtual = true only requests virtual threads. Java 17 has none, so the executor uses platform threads. The application behaves correctly, just without the scalability of virtual threads.
Previous: Virtual Threads in Spring Boot: Configuration, Pitfalls and Monitoring
Next: Modern Java Concurrency: Key Takeaways and an Adoption Checklist

More in Modern Java Concurrency
Quiz: Java Concurrency Changes From Java 21 to Java 28
Sixteen questions on what changed release by release: virtual threads final in 21, synchronized without pinning in 24, scoped values final in 25, and the long road of structured concurrency from subclasses to open() and Joiner, the Java 26 and 27 refinements, and final in 28.
Quiz: Java Concurrency's Delicate Details
Twenty edge cases of modern Java concurrency that surprise experienced developers: virtual thread priorities and names, semaphores without owners, null scoped values, cancelling a CompletableFuture, pool sizing with unbounded queues, and StructuredTaskScope's strict rules.
Quiz: Java Concurrency Interview Questions (Virtual Threads, Structured Concurrency, Scoped Values)
Twenty questions of the kind interviewers ask about modern Java concurrency: platform vs virtual threads, pinning, pools and limits, CompletableFuture, structured concurrency, scoped values vs ThreadLocal, reactive programming, and production diagnostics.
Quiz: Modern Java Concurrency Final Exam (All 7 Parts)
The final exam for the modern Java concurrency course: thirty questions across all seven parts, from platform threads, pools and CompletableFuture through virtual threads, the scheduler, structured concurrency, scoped values, reactive streams and frameworks.
Discussion
Sign in to ask a question or share what you learned.