Koskamo

Virtual threads for concurrent throughput

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Platform threads incur nontrivial costs, requiring thousands of CPU instructions to start and consuming megabytes of memory, making separate platform threads infeasible for high-concurrency server applications. Instead of non-blocking APIs with deeply nested callbacks, use virtual threads to make blocking cheap. Since Java 21, virtual threads allow familiar structures like branches and loops during I/O waits, as the underlying platform thread unmounts the blocking virtual thread to run others. Utilize Executors.newVirtualThreadPerTaskExecutor() to create an ExecutorService handling large numbers of concurrent, I/O-blocking tasks. Avoid virtual threads for CPU-intensive work; use parallel streams or recursive fork-join tasks instead. Note that while JEP 425 introduced them in Java 19, they transitioned through preview in Java 20 before finalization. Scope: Java. Reviewed October 4, 2026.

Source and provenance

Original source
dev.java
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.