Project Loom, delivered in Java 21, fundamentally changes how Java handles concurrency. Virtual threads enable millions of concurrent tasks without thread pooling overhead, while structured concurrency and scoped values make concurrent code safer and more maintainable.
0 / 5 completed
1 / 5
What is the key architectural difference between a virtual thread and a platform thread in Project Loom?
Virtual threads are cheap, JVM-managed threads that are mounted on carrier (OS) threads only when actively executing. This allows millions of concurrent virtual threads without the memory overhead of a matching number of OS threads.
2 / 5
In Structured Concurrency (JEP 428/462), what guarantee does a StructuredTaskScope provide?
StructuredTaskScope enforces a parent-child lifetime relationship: the scope acts as a boundary that is not exited until all forked subtasks complete or are cancelled, making concurrent code easier to reason about and prevent leaks.
3 / 5
A virtual thread calls a synchronized method that blocks on I/O. What happens in Java 21?
In Java 21, synchronized blocks and methods can pin the carrier thread, preventing it from running other virtual threads during the blocking operation. This is a known limitation; using ReentrantLock instead avoids pinning.
4 / 5
What problem do ScopedValues solve compared to ThreadLocal when using virtual threads?
ScopedValues are designed for the Loom era: they are immutable within a scope and automatically unavailable outside it. ThreadLocal is mutable and inherited by child threads, which creates subtle bugs at scale with millions of virtual threads.
5 / 5
Which interface, added in Java 21, provides a unified ordered view of the first and last elements of a collection?
SequencedCollection (JEP 431, Java 21) adds methods like getFirst(), getLast(), addFirst(), and reversed() to collections that have a well-defined encounter order, unifying APIs across List, Deque, and LinkedHashSet.