Java 21 in Practice, Virtual Threads, Structured Concurrency, and Scoped Values

omgzui
Javarevisited
Published in
8 min readJun 22, 2023

--

Photo by Clément Hélardot on Unsplash

If you still think that there is no need to toss about the previous JDK17, then JDK21 needs to pay attention. Because JDK21 introduces a new type of concurrent programming model.

The current multi-threaded concurrent programming in Java is another part of our headaches. It feels like it is difficult to learn and difficult to use. But looking back at friends who use other languages, there is no such trouble at all, such as GoLang, it feels very silky to use.

JDK21 has made great improvements in this area, making Java concurrent programming a little easier and smoother. To be precise, there are these improvements in JDK19 or JDK20.

Among them, Virtual Threads, Scoped Values, and Structured Concurrency are several functions for multi-threaded concurrent programming.

1. Virtual Threads

Virtual threads are coroutine-based threads that have similarities to coroutines in other languages but also have some differences.

The virtual thread is attached to the main thread. The virtual thread will no longer exist if…

--

--

omgzui
Javarevisited

A full stack engineer, with some medicinal knowledge, likes to read and share.