virtual thread

A lightweight thread scheduled by the JVM onto a small pool of carrier platform threads.

In more detail

Virtual threads are cheap enough to create one per task and should not be pooled. They are always daemon threads. Blocking parks the virtual thread and frees its carrier, except when pinned, as inside synchronized code in Java 21.

Example

try (var ex = Executors.newVirtualThreadPerTaskExecutor()) {
    ex.submit(() -> work());
}

Related terms

Taught in

References

Certification courses