DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Java Is Greener on Arm
  • Mastering Date/Time APIs: Challenges With Java's Calendar and JDK Date/Time APIs
  • Java 23: What Developers Need to Know

Trending

  • Java 23 Features: A Deep Dive Into the Newest Enhancements
  • A Guide to Container Runtimes
  • Segmentation Violation and How Rust Helps Overcome It
  • Building Scalable and Resilient Data Pipelines With Apache Airflow
  1. DZone
  2. Coding
  3. Java
  4. The Resurrection of Virtual Threads: Unraveling Their Journey From JDK 1.1 to JDK 21

The Resurrection of Virtual Threads: Unraveling Their Journey From JDK 1.1 to JDK 21

As we move forward, virtual threads provide an efficient concurrency model, propelling Java into a new era of multi-threading.

By 
Roopa Kushtagi user avatar
Roopa Kushtagi
·
Nov. 15, 23 · Opinion
Likes (10)
Comment
Save
Tweet
Share
5.8K Views

Join the DZone community and get the full member experience.

Join For Free

A few months ago, I penned an article discussing the debut of virtual threads in JDK 21 and their role in enabling the thread-per-request pattern. You can access the full article here.

During my interactions with the readers, I uncovered an intriguing historical tidbit: virtual threads had been introduced previously, way back in the days of JDK 1, only to be subsequently phased out.

To be candid, this was news to me, given my Java journey began in the early 2000s. My curiosity piqued, and I embarked on a quest for insights into the initial introduction and subsequent discontinuation of virtual threads, leading to their remarkable resurgence in JDK 21.

In this article, I will reveal the insights I unearthed during my quest.

Green threads, also known as virtual threads or user-level threads, were originally used in early versions of Java, including JDK 1.0, for concurrency. These threads are managed by a user-level library or runtime system rather than the underlying operating system. They were designed to provide a lightweight way of achieving concurrency without relying on the operating system's native threads.

thread management

However, there were several reasons why green threads were dropped after JDK 1.0 in favor of native threads:

  1. Platform independence: Java's "write once, run anywhere" promise was challenging to uphold with green threads. Green threads were highly dependent on the underlying runtime system, making it difficult to maintain platform independence.
  2. Limited concurrency: Green threads were not well-suited for applications that required true parallelism, especially on multi-core processors. They couldn't take full advantage of the available hardware resources.
  3. Scalability: Green threads could not fully leverage modern hardware, as they relied on a single process to handle all threads. Native threads or platform threads, on the other hand, can be distributed across multiple processes.
  4. Blocking I/O: Green threads couldn't efficiently handle blocking I/O operations. When a green thread blocked on I/O, it would often block all other threads in the process, causing poor performance.
  5. Portability: Applications using green threads could behave differently on different platforms, making it challenging to ensure consistent behavior across various systems.
  6. Operating system support: As Java evolved, the use of native threads became more practical due to improvements in operating system support for multithreading. Native threads offered better performance and compatibility with modern systems.

Due to these limitations, Java shifted towards using native threads to improve performance, scalability, and portability. This change resulted in better support for concurrent and parallel programming, making Java more suitable for a wider range of applications and systems.

In JDK 21, Java introduced a new concurrency model based on virtual threads, which can be seen as a reimagined version of green threads. These virtual threads aim to address some of the challenges that green threads faced in earlier versions of Java. While they share similarities with green threads, they are designed with modern solutions in mind. Here's how they address the challenges mentioned:

  1. Platform independence: Virtual threads maintain platform independence. They are integrated into the Java platform itself and do not rely on external user-level libraries. This ensures that the "write once, run anywhere" principle is upheld.
  2. Limited concurrency: Virtual threads can provide more concurrency than green threads. They are designed to take advantage of modern multi-core processors, allowing for better parallelism and performance.
  3. Scalability: Virtual threads can be efficiently scheduled across multiple processors and cores, making them suitable for modern hardware with high scalability.
  4. Blocking I/O: Virtual threads can efficiently handle blocking I/O operations. When a virtual thread blocks on I/O, it is automatically suspended without affecting the execution of other virtual threads. This improves performance in applications with I/O-bound tasks.
  5. Portability: The behavior of virtual threads is consistent across different platforms, ensuring that applications using virtual threads will have predictable and reliable performance.
  6. Operating system support: JDK 21 is designed to work with native threads when necessary, ensuring good compatibility with modern operating systems. It strikes a balance between virtual threads and native threads to optimize performance and resource utilization.

While virtual threads draw inspiration from green threads, they are not a complete reversion to the old green thread model. Instead, they combine the best aspects of both green threads and native threads to provide a more versatile and efficient concurrency model. This approach allows Java to better adapt to contemporary hardware and address the challenges that green threads faced in earlier versions of the language.

Java Development Kit Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Java Is Greener on Arm
  • Mastering Date/Time APIs: Challenges With Java's Calendar and JDK Date/Time APIs
  • Java 23: What Developers Need to Know

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!