Friends of OpenJDK Today

Loom is just HyperThreading in Java

November 14, 2023

Author(s)

  • Johannes Bechberger
    Johannes Bechberger

    A JVM developer working on profilers and their underlying technology, e.g. JEP Candidate 435, in the SapMachine team at SAP.

While sitting in Cay Horstmann's "Looming Changes in Java Concurrency" talk at BaselOne, I had an epiphany: Aren't virtual threads with Loom just a version of HyperThreading on the JVM?

Both try to utilize a computation resource fully, be it hardware core or platform thread, by multiplexing multiple tasks onto it, despite many tasks waiting regularly for IO operations to complete:

When one task waits, another can be scheduled, improving overall throughput. This works especially well when longer IO operations follow short bursts of computation.

There are, of course, differences between the two, most notably: HyperThreading doesn't need the tasks to cooperate, as Loom does, so a virtual core can't starve other virtual cores. Also noteworthy is that the scheduler for Hyper-Threading is implemented in silicon and cannot be configured or even changed, while the virtual thread execution can be targeted to one's needs.

I hope you found this small insight helpful in understanding virtual threads and putting them into context. You can find more about these topics in resources like JEP 444 (Virtual Threads) and the "Hyper-Threading Technology Architecture and Microarchitecture" paper.

This article is part of my work in the SapMachine team at SAP, making profiling and debugging easier for everyone. This article appeared originally on my personal blog mostlynerdless.de.

Topics:

Related Articles

View All

Author(s)

  • Johannes Bechberger
    Johannes Bechberger

    A JVM developer working on profilers and their underlying technology, e.g. JEP Candidate 435, in the SapMachine team at SAP.

Comments (4)

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

Highlight your code snippets using [code lang="language name"] shortcode. Just insert your code between opening and closing tag: [code lang="java"] code [/code]. Or specify another language.

Save my name, email, and website in this browser for the next time I comment.

Andrew Schetinin

I have a feeling that these two things complement each other and not contradict. IMO they exist on different architectural levels.
Virtual threads in Java (together with structured concurrency – JEP 437) greatly simplify writing non-blocking multithreaded code.
Technically, at the bottom, hyperthreaded hardware runs it all the same – it does not care what it executes.
With Java virtual threads and structured concurrency developing scalable applications becomes much easier.

Johannes Bechberger
Johannes Bechberger

I agree, structured concurrency will make Project Loom far more useful. Currently it is just useful for a small portion of all use cases of multi-threading.

Alex

i’m honestly confuse, while i know it’s really great improvement java will have virtual threads.
But isn’t kotlin already achieve virtual threads, just by using normal thread on java?

Johannes Bechberger
Johannes Bechberger

Kotlin’s virtual threads are implemented differently and offer different pro’s and con’s. There are many great resources out there covering the differences, for example https://www.baeldung.com/kotlin/java-kotlin-lightweight-concurrency.

Subscribe to foojay updates:

https://foojay.io/feed/
Copied to the clipboard