This talk introduces the concepts of virtual threads and structured concurrency in Java. It explains how virtual threads enable Structured Concurrency and then compares the current concurrency API (CompletableFuture) with Structured Concurrency API with multiple examples.
Virtual Threads are lightweight user threads. They can be created easily and in abundance. Also, they don’t block platform threads and this means we can use them to represent concurrent business-tasks in our domain and structure them in a way that the programs resemble more to the domain-requirements thus enabling Structured Concurrency.
Structured Programming has made reading and understanding programs easier by introducing a set of control structures. Similarly Structured Concurrency introduces control structures for concurrent programs and makes them easy to read and understand.
This talk also discusses a few examples where CompletableFuture API is compared with Structured Concurrency API by live-coding their implementations. Overall, these examples highlight that CompletableFuture’s reactive-like API relies on callbacks whereas Structured Concurrency puts forward an imperative-like API which is easier to read and reason.