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
- thread — A path of execution inside a process that the operating system schedules on a processor; one process can have many.
- pinning — Fixing an exact version or digest of something you depend on so it cannot change without you noticing.
- ExecutorService — The standard-library service that owns a pool of worker threads and runs tasks you submit to it, returning a Future for each.
Taught in
- Jars, Automatic Modules And Runtime Images — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Platform And Virtual Threads, Runnable And Callable — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Thread Safety: Locks And Atomics — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Modules And Concurrency — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Mock Exam: Sit It, Score It — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep