

Structured concurrency: will Java Loom beat Kotlin’s coroutines?
source link: https://xebia.com/structured-concurrency-will-java-loom-beat-kotlins-coroutines/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Kotlin and Java Loom: structured concurrency for the masses
Java, as slow adopter of new concepts is getting structured concurrency as part of the Loom project. This addition enables native support for coroutines (termed virtual threads) in Java. What does that mean for Java & Kotlin developers? Should we now all transform our existing code bases to support virtual threads? Or even jump back to Java? We compare two approaches to do structured concurrency on the JVM: Java Loom’s virtual threads and Kotlin’s coroutines. As it turns out, Kotlin coroutines show to be more developer friendly, while Java Loom might have its sweet spot as part of Java libraries and frameworks. Want to know why? Buckle up, as we have a lot to talk about!
My colleague and Kotlin specialist Urs Peter suggested to look into Loom and compare it to Kotlin coroutines. We did that on one of our (awesome, I might add) innovation days
There we realised that Java is not only a programming language, but also a platform. Actually you could see it the other way around. The Java programming language is the reference implementation for the Java platform. This is breaking news, because this concept gives you the opportunity to hate Java in two different ways…
Haha, just joking. But all jokes aside, this split view on Java puts Loom in the position of one of the most impactful Java projects. But also one of the most silent ones. Loom extends the JVM with structured concurrency with only minor changes to the programming language. So what is Loom exactly and what does it have to do with Kotlin?


Hello world 2
Hello world 1
coroutineScope { // <---- only needed on top-level
launch {
delay(500)
println("Hello world 1")
}
println("Hello world 2")
}
The structured concurrency constructs of Kotlin map in most cases “more or less” to the Java-Loom constructs:
coroutineScope ~ try (ExecutorService exs = Executors.newVirtualThreadExecutor())
launch -> exs.submit(...)
async & await -> Future<...> f = exs.submit(...) & f.join()
sadfasdf
<?php
echo "Hi, I'm a PHP script!";
?>
Recommend
-
49
Kotlin Expertise Blog - Concurrent Coroutines - Concurrency is not Parallelism - Kotlin coroutines focus on concurrency + structure rather than parallelism
-
8
Rx to Coroutines Concepts, Part 2: Structured Concurrency Posted by Bill Phillips on July 13, 2021 Check out part 1 on differences in preemptibility...
-
9
Kotlin and Java Loom: structured concurrency for the masses Java, as slow adopter of new concepts is getting structured concurrency as part of the Loom project. This addition enables native support for coroutines (termed virtual t...
-
8
Things every Kotlin Developer should know about Coroutines. Part 3: Structured Concurrency.Subscribe to my newsletter and never miss my upcoming articles
-
4
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 altern...
-
6
Java Concurrency: An Introduction to Project Loom Poste...
-
5
Applying Kotlin Structured Concurrency: Part III — Exceptions in coroutinesIn Java and Kotlin you can use try/catch for catch exceptions.If you don’t handle an exception in a meth...
-
7
Coroutines and Loom behind the scenes by Roman Elizarov ...
-
11
Structured concurrency helps to cancel coroutines not only individually one by one but also centralised using root coroutine — cancelation of parent coroutine canceling child coroutines too.CancellationExcepti...
-
7
Structured Concurrency for Coroutines: Unraveling the Fundamentals6 min readDec 26, 2023Concurrency
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK