Categories
Featured Guest Post Java Language Tech News Uncategorized

The Java Concurrency Model: Project Loom Introduces Lightweight and Efficient Virtual Threads Called Fibers

Lightweight and efficient virtual threads called fibers have been introduced by Project Loom, massively increasing resource efficiency while preserving the same simple thread abstraction for developers.

Loom is an up-and-coming project in the Java/JVM ecosystem (hosted by OpenJDK) that aims to offer a more practical approach than traditional threads. It does this with new language constructs for managing them and some lighter alternatives.

The project will accomplish this by adding these new constructs:

  • Virtual threads
  • Delimited continuations
  • Tail-call elimination

The Fiber class is a virtual thread that allows developers to use asynchronous Acrobatics. This under-the-hood work will make it easier for them, as well as provide an opportunity of moving forward with existing code without too much trouble or confusion about how things should be done differently now because there’s some new framework available called “Fiber.”

A very simple example of using fibers is shown below:

Thread.startVirtualThread(
  () -> {
    System.out.println("Hello World");
  }
);

Loom’s fibers are different than any other concurrent programming model, but they’re not meant to break your code. This is a rather Herculean task, given how much needs change in order for everything just to work better with fibers- but they’re committed! You don’t need any more than what’s already there; all your threads should continue working fine even after adopting this new system.

Project: https://wiki.openjdk.java.net/display/loom/Main

References:

  • https://blogs.oracle.com/javamagazine/post/going-inside-javas-project-loom-and-virtual-threads
  • https://www.infoworld.com/article/3652596/project-loom-understand-the-new-java-concurrency-model.html

By Shobha Kakkar

Young motivated tech-business professional looking forward to make career in AI and IoT.

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version