Project Loom: Understand the new Java concurrency model

Loom is a newer project in the Java / JVM ecosystem (hosted by OpenJDK) that attempts to address limitations in the traditional concurrency model. In particular, Loom offers a lighter alternative to threads along with new language constructs for managing them.

Read on for an overview of these important upcoming changes.

Fibers: Virtual threads in Java

Traditional Java concurrency is managed with the Thread and Runnable classes, as seen in Listing 1 (which launches a new named thread and outputs the name).

Listing 1. Launching a thread with traditional Java

Thread thread = new Thread("My Thread") {
      public void run(){
        System.out.println("run by: " + getName());

This model is fairly easy to understand in simple cases, and Java offers a wealth of support for dealing with it.

The downside is that Java threads are mapped directly to the threads in the OS. This places a hard limit on the scalability of concurrent Java apps. Not only does it imply a one-to-one relationship between app threads and operating system threads, but there is no mechanism for organizing threads for optimal arrangement. For instance, threads that are closely related may wind up sharing different processes, when they could benefit from sharing the heap on the same process.

To give you a sense of how ambitious the changes in Loom are, current Java threading, even with hefty servers, is counted in the thousands of threads (at most). Loom proposes to move this limit towards million of threads. The implications of this for Java server scalability are breathtaking, as standard request processing is married to thread count.

Copyright © 2022 IDG Communications, Inc.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button
KQ Education Group