This paper investigates Java virtual threads and their efficiency in parallel programming compared to non-virtual threads.
ABSTRACT
The Java programming language, in its long-term support version 21 (released in September 2023), introduced a new type of Java threads known as virtual threads. While Java non-virtual (or platform) threads are mapped one-to-one to operating system threads, multiple virtual threads can be executed on a single platform thread, i.e. on a single operating system thread, which makes the number of virtual threads practically unlimited.
These threads make it possible to write code that is as efficient as asynchronous code, while remaining more readable, easier to debug, and providing clearer error messaging (exceptions) compared to traditional asynchronous approaches.
Virtual threads are often highlighted as primarily intended for concurrent programming (for example, assigning each active user on an application server a separate thread) and are less suited for parallel programming (where a task is divided into subtasks to utilize the processing power of multiprocessor systems).
This paper analyzes the efficiency of these virtual threads in parallel programming.