Nobody Talks About Project Loom
Author
Marcus HeldHi,
“Why isn’t anyone talking about Project Loom?
On the JVM, one of the largest changes in years is looming over us.
And it will massively influence the way we work.
Asynchrony is difficult. There’s so much to consider:
How do I configure my thread pool? Does the code path have more wait-time, or does it take a long time to calculate? And how large should the queue be in front of the thread pool? Are spikes in the code path to be expected?
And how do I actually get my global state, like the SecurityContext
or the MDC over it?
Oh yes, I also lose the stack trace - which makes debugging more of a nuisance.
And if I switch from the “Thread-per-Request” model to a reactive implementation (like Webflux/Reactor), it gets even more complicated. The implementation independently decides on which thread what is executed. In this setting, side effects are super difficult to trace. And now the threads are no longer there for individual paths - but for (almost) everything.
This is not simpler. It’s more complicated. But - it’s ultimately more performant.
And now comes Project Loom. With the virtual threads, we can forget all this 😱
They are so inexpensive. Both in their static overhead and in their runtime. It doesn’t hurt at all when they wait. You can start millions of virtual threads, let them all sleep, and run a single one. You won’t notice. The implementation is fast!
This fundamentally changes how we can write our code.
In the old, boring “Thread-per-Request” model, we can suddenly program synchronously.
Do you need to address a service via REST? Doesn’t matter - just wait synchronously for the response.
Do you need data from the cold store archive? Doesn’t matter - we just wait until it’s warm.
And it’s so boring. We remain in the same thread. The stack trace is complete. The MVC tags are still there - of course.
This is the biggest change to our daily business in a long time.
It will be so much simpler. Most applications that switched to Webflux for performance reasons no longer need it.
But surprisingly, it’s super quiet around it.
On September 19th, with Java 21, it’s happening. I’m excited.”
Rule the Backend,
~ Marcus