@RunOnVirtualThread directs an annotated method to execute on a virtual thread. Placing it on a class applies the behavior to all of that class’s methods. section 8.5.1
Use the annotation with these execution expectations:
- Create a new virtual thread for each task instead of maintaining a reusable virtual-thread pool. section 8.5.1
- Expect virtual threads to be cheap to create, start, and reclaim after completing their work. section 8.5.1
- Request virtual-thread execution explicitly because Quarkus does not provide a global switch for every execution. section 8.5.2
@GET
@Path("/virtualThread")
@RunOnVirtualThread
public void virtualThread() {
Log.info("Running on " + Thread.currentThread().getName());
}
Annotate an HTTP endpoint with @RunOnVirtualThread and inspect the current thread from its handler. section 8.5.1
Observing execution
Repeated calls to an annotated endpoint can report names such as quarkus-virtual-thread-0, quarkus-virtual-thread-1, and quarkus-virtual-thread-2, showing that each call uses a newly created virtual thread. section 8.5.1
Virtual threads are not a universal replacement for reactive execution. Transactions, ThreadLocal-dependent libraries, and pinning can make adoption difficult; when library compatibility is insufficient, Quarkus can switch to reactive programming. section 8.5.2
