Project Loom is a huge step forward in the way the JVM implements concurrency. It introduces a concurrency model that is straight forward to use without sacrificing scalability. It gets a lot of traction since it was released in preview mode in Java 19, however, it is not a silver bullet that will magically resolve everything. In this talk we will go through the essentials of the project and help understand when and where applying it will make your life as a Java developer significantly better.
4. Loom me up Scotty!
Project Loom - What's in it for Me?
Haim Yadid @ Next Insurance
5. Loom me up Scotty!
Project Loom - What's in it for Me?
Haim Yadid @ Next Insurance
Dall E - Star Trek spaceship Enterprise flying inside a loom, Van gogh style
19. Example - Single Threaded
val country = userClient.
findUserByEmail(userEmail).country
t1
https://github.com/lifey/loom-playground
20. Example - Single Threaded
val country = userClient.
findUserByEmail(userEmail).country
val resultA = serverA.getBid(country)
val resultB = serverB.getBid(country)
t1
21. Example - Single Threaded
val country = userClient.
findUserByEmail(userEmail).country
val resultA = serverA.getBid(country)
val resultB = serverB.getBid(country)
val lowestBid = if (resultA.price < resultB.price)
resultA
else
resultB
t1
32. traditional Java Concurrency Model
● Thread per request (task) style
● Java thread is a wrapper of OS thread
● 1 or more thread to serve the request using Futures
● Executors and thread pools to control concurrency level
48. So what is the Problem With OS Threads
● stack: ~1 MB
● scheduling >1µs
● launch a new thread ~0.1ms
● context switch involves kernel meaning returning from future
~5µs
● Usually Linux OS can support thousands of threads
94. But Maybe
● If you are starting to write a new service that is IO bound and
requires high level of concurrency (> 10K concurrent
connections)
● If you want to play around
○ https://github.com/lifey/loom-playground
○ https://github.com/cmpxchg16/kotlin-loom
● If you want to provide feedback
98. Helidon Nima
With “dumb”
synchronous code on
Loom and some
simple tuning, quickly
got similar or better
performance to Netty
— Tomas Langer
(Helidon)
101. Pinned Threads
● When a virtual thread is in a synchronized block
(or in JNI call)
● It cannot be unmounted
● Even when blocked on IO
-Djdk.tracePinnedThreads=full