JetbrainsMarit van DijkTutorial
Project Loom in IntelliJ IDEA: Virtual Threads, Scoped Values, and Structured Concurrency
Summary
Project Loom in IntelliJ IDEA introduces Java developers to three cohesive concurrency features: Virtual Threads (JEP 444, stable since Java 21), Scoped Values (JEP 506, stable since Java 25), and Structured Concurrency (JEP 533, seventh preview in Java 27). The post identifies pain points such as CompletableFuture ignoring interrupt flags, manual ExecutionException unwrapping chains, duplicated cancel() calls across catch blocks, mutable ThreadLocal pitfalls, and flat thread dumps lacking request hierarchy. A CustomerProfileService example is refactored from CompletableFuture.allOf to StructuredTaskScope.ShutdownOnFailure, where sibling tasks are cancelled automatically and a single timeout covers the whole scope. IntelliJ IDEA debugger support from version 2026.1 groups virtual threads forked within a StructuredTaskScope into containers representing their scopes, and the post walks through downloading JDK 27 (EA) and enabling the experimental language level.
Context
Problems with Java concurrency before Project Loom: thread leaks from CompletableFuture ignoring interrupt flags, awkward ExecutionException unwrapping chains, duplicated cancel() logic across TimeoutException and ExecutionException catch blocks that must be kept in step, mutable ThreadLocal values prone to memory leaks, and flat thread dumps that show no parent-child relationship between pool threads.
Approach / What changed
Project Loom combines Virtual Threads for lightweight, JVM-managed concurrency, Scoped Values as an immutable, automatically cleaned-up replacement for ThreadLocal, and StructuredTaskScope.ShutdownOnFailure which treats sibling tasks as a single unit with automatic cancellation and unified error handling. IntelliJ IDEA 2026.1 surfaces the StructuredTaskScope hierarchy in thread dumps and provides inlay hints to download or configure the required JDK 27 (EA) build.
Takeaways
Project Loom combines three JEPs: Virtual Threads (JEP 444, stable since Java 21), Scoped Values (JEP 506, stable since Java 25), and Structured Concurrency (JEP 533, seventh preview in Java 27).
CompletableFuture.supplyAsync with cancel(true) ignores the interrupt flag for already-running tasks, so cancellation logic must be duplicated across both TimeoutException and ExecutionException catch blocks and manually extended whenever a new parallel call is added.
IntelliJ IDEA 2026.1 debugger groups virtual threads forked within a StructuredTaskScope into containers representing their scopes, exposing the parent-child hierarchy that was missing from traditional pool thread dumps.
Source and freshness
- Source
- blog.jetbrains.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.