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

Developing an Asynchronous Application with Vir...

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for José José
January 30, 2026

Developing an Asynchronous Application with Virtual Threads and Structured Concurrency

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. It consists in the guided, step by step refactoring of a legacy application to a modern Java application based on the use of Data Oriented Programming and Structured Concurrency. 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é

January 30, 2026
Tweet

More Decks by José

Other Decks in Education

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 © 2026, 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. 1/30/2026 Copyright © 2026, Oracle and/or its affiliates 11 Is

    it new? First ideas emerged in the early 60’s First specification for Fortran 1997 Structured Concurrency
  4. 1/30/2026 Copyright © 2026, Oracle and/or its affiliates 12 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. 1/30/2026 Copyright © 2026, Oracle and/or its affiliates 13 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. 1/30/2026 Copyright © 2026, Oracle and/or its affiliates 14 Closing

    ReportScope closes the other scopes A Scope can Spawn more Scopes ReportScope ImageScope LinkScope
  7. 1/30/2026 Copyright © 2026, Oracle and/or its affiliates 15 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. 1/30/2026 Copyright © 2026, Oracle and/or its affiliates 16 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

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

    its affiliates 18 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 1/30/2026 Copyright © 2026,

    Oracle and/or its affiliates 19 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

    1/30/2026 Copyright © 2026, Oracle and/or its affiliates 20 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
  13. Step 4 and 5 Step 3 Step 1 and 2

    1/30/2026 Copyright © 2026, Oracle and/or its affiliates 21 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 Step 6: set up a timeout Flight Company query Get all the flights Select the cheapest one
  14. Step 4 and 5 Step 3 Step 1 and 2

    1/30/2026 Copyright © 2026, Oracle and/or its affiliates 22 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 Step 6: set up a timeout Flight Company query Get all the flights Select the cheapest one Step 7: Manage a licence to query the server