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

Développer une Application Asynchrone avec l'AP...

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.
Avatar for José José
April 17, 2026

Développer une Application Asynchrone avec l'API Structured Concurrency

Une des fonctionnalités les plus intéressantes de Java 21 sont les Threads Virtuels, développés dans le cadre du projet Loom. L'object est d'autoriser à nouveau le modèle de programmation "un thread par requête" tout en utilisant les capacités CPU du serveur à 100%. Avant l'introduction des threads virtuels, ces performances ne pouvaient être atteintes qu'avec la programmation réactive, au prix de l'écriture d'une code peu lisible et difficile à maintenir. Ce lab vous propose d'écrire une application utilisant les threads virtuels et la programmation concurrente structurée afin de pouvoir lancer vos requêtes réseau en parallèle, et des scoped values pour passer certaines informations d'un point à l'autre de votre application autrement qu'en les passant en paramètres de méthodes. Vous mettrez en application les patterns de code que Loom met à votre disposition. Il vous sera alors possible de les comparer avec d'autres approches, notamment réactive, avec de choisir ce que vous préférez.

Avatar for José

José

April 17, 2026

More Decks by José

Other Decks in Programming

Transcript

  1. Développer une Application Asynchrone avec l'API Structured Concurrency The Loom

    Project José Paumard Java Developer Advocate Java Platform Group Pierre-Yves Fourmond Senior Java Developer & Tech Lead Octo Technology
  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. 4/17/2026 Copyright © 2026, Oracle and/or its affiliates 11 First

    ideas emerged in the early 60’s First specification for Fortran 1997 Structured Concurrency
  4. 4/17/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. 4/17/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. 4/17/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. 4/17/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. 4/17/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

    4/17/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 4/17/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 4/17/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

    4/17/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

    4/17/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

    4/17/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