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

Developing an Asynchronous Application with Vir...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Developing an Asynchronous Application with Virtual Threads and Structured Concurrency

The Loom project is to make asynchronous programming simpler, enabling 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.
In this lab, we'll guide you through writing a virtual thread-based web application that uses structured concurrency to parallelize requests, and implements different strategies to process them. Then you'll see how to use scoped values to pass sensitive info from one module of your application to another one, without relying on method parameters.
See the patterns of code the Loom project gives you to achieve the same throughput as a classical reactive application. You can then compare the code patterns of both approaches to choose which you prefer.

Avatar for José

José

March 16, 2026
Tweet

More Decks by José

Other Decks in Programming

Transcript

  1. Developing Async Applications Virtual Threads and Structured Concurrency José Paumard

    Java Developer Relation Java Platform Group, Oracle Ana-Maria Mihalceanu Sr Developer Advocate Java Platform Group, Oracle
  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. 3/17/2026 Copyright © 2026, Oracle and/or its affiliates 8 First

    ideas emerged in the early 60’s First specification for Fortran 1997 Structured Concurrency
  4. 3/17/2026 Copyright © 2026, Oracle and/or its affiliates 9 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. 3/17/2026 Copyright © 2026, Oracle and/or its affiliates 10 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. 3/17/2026 Copyright © 2026, Oracle and/or its affiliates 11 Closing

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

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

    its affiliates 15 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 3/17/2026 Copyright © 2026,

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

    3/17/2026 Copyright © 2026, Oracle and/or its affiliates 17 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

    3/17/2026 Copyright © 2026, Oracle and/or its affiliates 18 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

    3/17/2026 Copyright © 2026, 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 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