Project Loom: Revolution in Java Concurrency or Obscure Implementation Detail?

Project Loom: Revolution in Java Concurrency or Obscure Implementation Detail?

Installation charges of the Loon Balloon are very high. The entire setup is very costly ranging around $1.2 million for setup and $30,000/ year for maintenance. This technology would cut the cost and labor of expensive fiber cables that need to be dug deep in the ground. You can reach us directly at or you can also ask us on the forum. Deepu is a polyglot developer, Java Champion, and OSS aficionado.

  • It’s worth mentioning that virtual threads are a form of “cooperative multitasking”.
  • Those are technically very similar and address the same problem.
  • Trying to get up to speed with Java 19’s Project Loom, I watched Nicolai Parlog’s talk and read several blog posts.
  • The client Java process used 26 GB of committed resident memory and 49 GB of virtual memory.
  • That is what project Loom sets out to do, by introducing a new virtual thread class called a fiber.
  • In Java, each thread is mapped to an operating system thread by the JVM .

In Java, each thread is mapped to an operating system thread by the JVM . With threads outnumbering the CPU cores, a bunch of CPU time is allocated to schedule the threads on the core. If a thread goes to wait state (e.g., waiting for a database call to respond), the thread will be marked as paused and a separate thread is allocated to the CPU resource.

As have entire reactive frameworks, such as RxJava, Reactor, or Akka Streams. While they all make far more effective use of resources, developers need to adapt to a somewhat different programming model. Many developers perceive the different style as “cognitive ballast”. Instead of dealing with callbacks, observables, or flows, they would rather stick to a sequential list of instructions. I leave you with a few materials which I collected, more presentations and more articles that you might find interesting. Quite a few blog posts that explain the API a little bit more thoroughly.

On Project Loom, The Reactive Model And Coroutines

His hobbies playing Cricket and watching Hollywood movies. Earlier, we discussed the shortcomings of the OS scheduler in scheduling relatable threads on the same CPU. However, forget about automagically scaling up to a million of private threads in real-life scenarios without knowing what you are doing. The problem with real applications is them doing silly things, like calling databases, working with the file system, executing REST calls or talking to some sort of queue/stream.

However, it no longer runs, so it will be woken up by your operating system. A new version that takes advantage of virtual threads, notice that if you’re currently running a virtual thread, a different piece of code is run. With that model, every single time you create a user thread in your JVM, it actually creates a kernel thread.

In doing so, we also defined tasks and schedulers and looked at howFibers and ForkJoinPool could provide an alternative to Java using kernel threads. Project Loom proposes to solve this throughuser-mode threads which rely on Java runtime implementation of continuations and schedulers instead of the OS implementation. Project Loom is an experimental version of the JDK.

The operating system recognizes that the thread is waiting for I/O, and the scheduler switches directly to the next one. This might not seem like a big deal, as the blocked thread doesn’t occupy the CPU. However, each context switch between threads involves an overhead. This is far more performant than using platform threads with thread pools. Of course, these are simple use cases; both thread pools and virtual thread implementations can be further optimized for better performance, but that’s not the point of this post.

However, if you want to try it out, you can either check out the source code from Loom Github and build the JDK yourself, or download an early access build. To utilize the CPU effectively, the number of context switches should be minimized. From the CPU’s point of view, it would be perfect if exactly one thread ran permanently on each core and was never replaced. We won’t usually be able to achieve this state, since there are other processes running on the server besides the JVM. But “the more, the merrier” doesn’t apply for native threads – you can definitely overdo it. And yes, it’s this type of I/O work where Project Loom will potentially shine.

What’s new with Project Loon progress?

// The scope is a tool for creating nested continuations. It was supposed to be available in Java 17, we just got Java 18 and it’s still not there. I’m experimenting with Project Loom for quite some time already. Involved in open-source, DZone’s Most Valuable Blogger, used to be very active on StackOverflow.

Project Loom Solution

Do we have such frameworks and what problems and limitations can we reach here? Before we move on to some high level constructs, so first of all, if your threads, either platform or virtual ones have a very deep stack. With platform threads, the size of the stack trace is actually fixed. In real life, what you will get normally is actually, for example, a very deep stack with a lot of data.

The Problem With Project Loon

In other words, a continuation allows the developer to manipulate the execution flow by calling functions. The Loom docs present the example seen in Listing 3, which provides a good mental picture of how this works. This way, the balloons could fly at altitudes twice as high as commercial planes and beam down internet access to the communities below. You can think of it as having several cell towers floating around in the sky in your city and just connecting to the nearest one as they come and go like clouds. In 2013, Google officially unveiled this project and named it Project Loon. Note that the part that changed is only the thread scheduling part; the logic inside the thread remains the same.

This is just a minor addition to the API, and it may change. Essentially, a continuation is a piece of code that can suspend itself at any moment in time and then it can be resumed later on, typically on a different thread. You can freeze your piece of code, and then you can unlock it, or you can unhibernate it, you can wake it up on a different moment in time, and preferably even on a different thread.

These virtual threads actually reside on heap, which means they are subject to garbage collection. In that case, it’s actually fairly easy to get into a situation where your garbage collector will have to do a lot of work, because you have a ton of virtual threads. You don’t pay the price of platform threads running and consuming memory, but you do get the extra price when it comes to garbage collection. The garbage collection may take significantly more time.


Technically, you can have millions of virtual threads that are sleeping without really paying that much in terms of the memory consumption. This is a user thread, but there’s also the concept of a kernel thread. A kernel thread is something that is actually scheduled by your operating java project loom system. I will stick to Linux, because that’s probably what you use in production. For example, when a kernel thread runs for too long, it will be preempted so that other threads can take over. It more or less voluntarily can give up the CPU and other threads may use that CPU.

Project Loom Solution

It’s just that the API finally allows us to build in a much different, much easier way. However, it turns out, first of all, it’s very easy with that tool to show you the actual Java threads. Rather than showing a single Java process, you see all Java threads in the output.

ICO Development Benefits, Risks and Regulatory Measures

The frequency of maintenance is very uncomfortable. The project Loon would provide humanitarian support to places where there is no access to common communication networks due to restrictions on the free flow of information. In May-June 2014, Google experimented with its internet-based balloons. This was recorded as the first LTE experiment performed near the equator. If the thread executing handleOrder() is interrupted, the interruption is not propagated to the subtasks. In this case updateInventory() and updateOrder() will leak and continue to run in the background.

Why are some Java calls blocking?

Continuation is a programming construct that was put into the JVM, at the very heart of the JVM. There are actually similar concepts in different languages. When these features are production ready, it will be a big deal for libraries and frameworks that use threads or parallelism. Library authors will see huge performance and scalability improvements while simplifying the codebase and making it more maintainable. Most Java projects using thread pools and platform threads will benefit from switching to virtual threads.

If instead you create 4 virtual threads, you will basically do the same amount of work. It doesn’t mean that if you replace 4 virtual threads with 400 virtual threads, you will actually make your application faster, because after all, you do use the CPU. There’s not much hardware to do the actual work, but it gets worse. In that case, it’s actually possible that you will only have a handful of virtual threads that never allow any other virtual threads to run, because they just keep using the CPU. That’s the problem that’s already handled by platform threads or kernel threads because they do support preemption, so stopping a thread in some arbitrary moment in time.

Virtual threads may be new to Java, but they aren’t new to the JVM. Those who know Clojure or Kotlin probably feel reminded of “coroutines” (and if you’ve heard of Flix, you might think of “processes”). Those are technically very similar and address the same problem. However, there’s at least one small but interesting difference from a developer’s perspective. For coroutines, there are special keywords in the respective languages (in Clojure a macro for a “go block”, in Kotlin the “suspend” keyword). The virtual threads in Loom come without additional syntax.

Then, the handleOrder() method throws an exception when calling inventory.get(). Since it runs on its own thread, it can complete successfully. But now we have an issue with a mismatch in inventory and order.


If you’ve already heard of Project Loom a while ago, you might have come across the term fibers. In the first versions of Project Loom, fiber was the name for the virtual thread. It goes back to a previous project of the current Loom project leader Ron Pressler, the Quasar Fibers. However, the name fiber was discarded at the end of 2019, as was the alternative coroutine, and virtual thread prevailed. With virtual threads on the other hand it’s no problem to start a whole million threads. In response to these drawbacks, many asynchronous libraries have emerged in recent years, for example using CompletableFuture.

No Comments

Post a Comment