Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DevoxxBE 2026 Loom lab

Avatar for José José
October 04, 2026

DevoxxBE 2026 Loom lab

The Loom project is about making asynchronous programming simpler. The promise is to enable the "simple thread-per-request style to scale with near-optimal hardware utilization". Before virtual threads, this was only achievable with callback-based reactive programming. Loom first brought virtual thread in JDK 21 that makes the blocking of threads almost free. Along with it, it published the Scoped Values API in JDK 25, as a replacement of the Thread Local API. The last element is the Structured Concurrency API, which is still a preview feature in JDK 26 and 27. This hands-on lab guides you through writing a virtual thread-based web application that utilizes structured concurrency to parallelize requests, and implements different strategies to process them. Then it shows you how you can use scoped values to pass sensitive information from one module of your application to another one, without relying on method parameters. It also uses the principles of Data Oriented Programming to organize your application in a simple way. You will use StructuredTaskScopes, the implementations of the Joiner interface that the API gives you, and you will create your own implementations as well. In the end, you will see the patterns of code that the Loom project gives you to achieve the same throughput as a classical reactive application, and you will then be able to compare both approaches to choose which one you prefer.

Avatar for José

José

October 04, 2026

More Decks by José

Other Decks in Programming

Transcript

  1. Using Structured Concurrency and Scoped Values to Create a Virtual

    Threads Based Asynchronous Application The Loom Project José Paumard Java Developer Advocate Java Platform Group Ana-Maria Mihalceanu Senior Developer Advocate Java Platform Group
  2. Tune in! Inside Java Newscast Inside.java JEP Café 6 Inside

    Java Podcast Road To 25 series Java 27 Launch Cracking the Java coding interview Copyright © 2026, Oracle and/or its affiliates 10/4/2026 Sip of Java
  3. OpenJDK is the place where it all happens https://jdk.java.net/ 8

    Copyright © 2026, Oracle and/or its affiliates 10/4/2026
  4. Structured Concurrency Is it new? First ideas emerged in the

    early 60’s First specification for Fortran 1997 11 Copyright © 2025, Oracle and/or its affiliates 10/4/2026
  5. Why is This Problem Interesting? Because it is about launching

    different tasks in different threads with an imperative programming model But… you need to be able to create threads on demand to implement it Made possible with virtual threads! 12 Copyright © 2025, Oracle and/or its affiliates 10/4/2026
  6. Stuctured Concurrency Pattern try (var scope = StructuredTaskScope.open()) { var

    linksSubTask = scope.fork(SomeService::readLinks); var imageSubTask = scope.fork(SomeService::readImages); scope.join(); var links = linksSubTask.get(); var images = imageSubTask.get(); var report = new Report(links, images); return report; } 13 Copyright © 2025, Oracle and/or its affiliates 10/4/2026
  7. A Scope can Spawn more Scopes ReportScope LinkScope ImageScope Closing

    ReportScope closes the other scopes 14 Copyright © 2025, Oracle and/or its affiliates 10/4/2026
  8. Goal of the lab You get a legacy application that

    is a Travel Agency web application that sells travels And that wants to display the weather forecast 3 servers: - A Flight Company server - A Weather forecast server - Your Travel Agency server 15 Copyright © 2025, Oracle and/or its affiliates 10/4/2026
  9. Structure of the Lab: Step 0 This is the current

    state of the application And it is terrible! Some refactoring needs to be done It uses the Data Oriented Programming approach 16 Copyright © 2025, Oracle and/or its affiliates 10/4/2026
  10. The Travel Agency Application Step 6: combine the weather and

    a travel with a third structured task scope Step 1, 2: use Structured Concurrency to query a travel Flight Company query Get all the flights Select the cheapest one Step 3: add a timeout and deal with it 17 Combine a flight and the weather on a single page. Prioritize the flight. Copyright © 2025, Oracle and/or its affiliates Step 4: create a cusom Joiner Step 7: use scoped values to send a licence key to the weather forecast server Get the first Weather forecast query Step 5: query the weather with a second structured task scope 10/4/2026