Comparison of Java Virtual and Non-Virtual Threads in Parallel Programming

The Java programming language, in its long-term support version 21 (released in September 2023), introduced Java virtual threads (prior to version 21, this was a prototype solution). While Java non-virtual (or platform) threads are mapped one-to-one to operating system threads, multiple Java virtual threads can be executed on a single platform thread, i.e. on a single operating system thread, which makes the number of Java virtual threads practically unlimited. Java virtual threads enable writing code that is as efficient as asynchronous code but is more readable, much easier to debug, and provides clearer error messaging (exceptions) compared to asynchronous code. It is often stated that virtual threads are primarily intended for concurrent programming (e.g. each active user on an application server can now be assigned a separate virtual thread) and are less suited for parallel programming (where a task is divided into subtasks to utilize the processing power of multiprocessor systems). In this paper, we analyze the efficiency of virtual threads specifically in parallel programming (counting prime numbers that are less than a given number and the goal was not to create a particularly efficient program, but to compare different methods). First, we demonstrate the use of non-virtual Java threads in Java versions 5/6 (Executors), Java 7 (Fork Join framework), and Java 8 (Parallel Streams), and then we modify the Java 5/6 program (with very simple changes) to an equivalent program using Java 21 virtual threads. It was found that Java 21 virtual threads were slightly slower in our case than the solution using non-virtual threads.

Authors

Institutions

Publication Details

Published
2025-06-02
DOI
https://doi.org/10.1109/mipro65660.2025.11131818
Primary Topic
Distributed and Parallel Computing Systems
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Comparison of Java Virtual and Non-Virtual Threads in Parallel Programming

Siniša Sovilj, Zlatko Sirotić, Matija Oršulić, Krešmir Pripužić
Distributed and Parallel Computing Systems
article

Comparison of Java Virtual and Non-Virtual Threads in Parallel Programming

Siniša Sovilj, Zlatko Sirotić, Matija Oršulić, Krešmir Pripužić
article en

Abstract

The Java programming language, in its long-term support version 21 (released in September 2023), introduced Java virtual threads (prior to version 21, this was a prototype solution). While Java non-virtual (or platform) threads are mapped one-to-one to operating system threads, multiple Java virtual threads can be executed on a single platform thread, i.e. on a single operating system thread, which makes the number of Java virtual threads practically unlimited. Java virtual threads enable writing code that is as efficient as asynchronous code but is more readable, much easier to debug, and provides clearer error messaging (exceptions) compared to asynchronous code. It is often stated that virtual threads are primarily intended for concurrent programming (e.g. each active user on an application server can now be assigned a separate virtual thread) and are less suited for parallel programming (where a task is divided into subtasks to utilize the processing power of multiprocessor systems). In this paper, we analyze the efficiency of virtual threads specifically in parallel programming (counting prime numbers that are less than a given number and the goal was not to create a particularly efficient program, but to compare different methods). First, we demonstrate the use of non-virtual Java threads in Java versions 5/6 (Executors), Java 7 (Fork Join framework), and Java 8 (Parallel Streams), and then we modify the Java 5/6 program (with very simple changes) to an equivalent program using Java 21 virtual threads. It was found that Java 21 virtual threads were slightly slower in our case than the solution using non-virtual threads.

University of Zagreb (HR), Juraj Dobrila University of Pula (HR)
Openalex Percentile: Top 74%
Distributed and Parallel Computing Systems
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.