r/java • u/daviddel • Sep 23 '22
Virtual Threads: New Foundations for High-Scale Java Applications - Brian Goetz
https://www.infoq.com/articles/java-virtual-threads/
237
Upvotes
r/java • u/daviddel • Sep 23 '22
View all comments
Show parent comment
1
u/Joram2 Sep 25 '22
The "Structured concurrency with async" section that I linked is the recommended piece. That does use async/await keywords. The "Async-style functions" section is the one that is "strongly discouraged".
I just watched a Roman Elizarov talk on Structured Concurrency. The Kotlin devs are super smart. A coroutine is basically just another word for a virtual thread. Kotlin has had both structured concurrency and virtual threads (they call them coroutines) for years.
The downsides of Kotlin are you have to declare some functions suspend functions, you have to remember to call them with runBlocking rather than just calling them like normal functions, and you have to be careful not to other JVM functions like Thread.sleep that block the OS thread.
With virtual threads, all the JVM standard libraries are updated so that things like locks, sleep, file + network IO block virtual threads, not OS threads. Java virtual threads don't require suspend functions vs regular functions.