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

Devoxx BE 2025 Loom lab

Avatar for José José
October 02, 2025

Devoxx BE 2025 Loom lab

One of the most exciting features delivered by JDK 21 are Virtual Threads, developed by the Loom project. They promise to enable the "simple thread-per-request style to scale with near-optimal hardware utilization". Before Virtual Threads, this could only be achieved with reactive programming, which provides excellent throughput, but with patterns that are difficult to write, read, debug, and profile. It offers outstanding performance, but at the expense of maintainability. This hands-on lab guides you through writing a virtual thread-based application that utilizes structured concurrency to parallelize requests and scoped values to pass sensitive information without relying on method parameters. You will see the patterns of code that the Loom project gives you to achieve the same throughput as a classical reactive application. You will then be able to compare the code patterns of both approaches to choose which one you prefer.

Avatar for José

José

October 02, 2025
Tweet

More Decks by José

Other Decks in Programming

Transcript

  1. Developing Async Applications with Virtual Threads and Structured Concurrency The

    Loom Project José Paumard Java Developer Advocate Java Platform Group Ana-Maria Mihalceanu Senior Developer Advocate Java Platform Group
  2. Tune in! 5 Copyright © 2025, Oracle and/or its affiliates

    | Inside Java Newscast JEP Café Road To 25 series Inside.java Inside Java Podcast Sip of Java Cracking the Java coding interview
  3. 10/7/2025 Copyright © 2025, Oracle and/or its affiliates 10 Is

    it new? First ideas emerged in the early 60’s First specification for Fortran 1997 Structured Concurrency
  4. 10/7/2025 Copyright © 2025, Oracle and/or its affiliates 11 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! Why is This Problem Interesting?
  5. 10/7/2025 Copyright © 2025, Oracle and/or its affiliates 12 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; }
  6. 10/7/2025 Copyright © 2025, Oracle and/or its affiliates 13 Closing

    ReportScope closes the other scopes A Scope can Spawn more Scopes ReportScope ImageScope LinkScope
  7. 10/7/2025 Copyright © 2025, Oracle and/or its affiliates 14 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 Goal of the lab
  8. 10/7/2025 Copyright © 2025, Oracle and/or its affiliates 15 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 Structure of the Lab: Step 0
  9. Step 0: get to know the application and refactor it

    10/7/2025 Copyright © 2025, Oracle and/or its affiliates 16 The Travel Agency Application Basic Flight Company query Basic Weather forecast query Basic combination of Flight and Weather forecast
  10. Step 1 and 2 10/7/2025 Copyright © 2025, Oracle and/or

    its affiliates 17 The Travel Agency Application Flight Company query Get all the flights Select the cheapest one Basic Weather forecast query Basic combination of Flight and Weather forecast
  11. Step 3 Step 1 and 2 10/7/2025 Copyright © 2025,

    Oracle and/or its affiliates 18 The Travel Agency Application Flight Company query Get all the flights Select the cheapest one Weather forecast query Get the first Cancel the others Basic combination of Flight and Weather forecast
  12. Step 4 and 5 Step 3 Step 1 and 2

    10/7/2025 Copyright © 2025, Oracle and/or its affiliates 19 The Travel Agency Application Travel Agency application Get the cheapest flight Check if the weather forecast is there If not, cancel it Weather forecast query Get the first Cancel the others Flight Company query Get all the flights Select the cheapest one