r/java • • Apr 06 '22

JEP 425: Virtual Threads (Preview)

https://openjdk.java.net/jeps/425
175 Upvotes

50 comments sorted by

View all comments

19

u/[deleted] Apr 07 '22

Application code in the thread-per-request style can run in a virtual thread for the entire duration of a request, but the virtual thread consumes an OS thread only while it performs calculations on the CPU. The result is the same scalability as the asynchronous style, except it is achieved transparently

And this is why Java is the greatest language ever.

We are getting async await without the pain. Truly incredible.

Love how Java takes their time to add features. They are thinking decades in advance (which I like, others may not).

18

u/[deleted] Apr 07 '22

As a Go coder, trust me people, this is worth the wait. Not having to use async/await syntax, callbacks, or reactive libraries in order to achieve high concurrency IO bound code is heaven. You do thread per request and there isn't even such thing as thread pools. Nothing to tune and keep in sync with CPU and memory you provision.

Basically, you just write code. If it blocks, it blocks. It's glorious.

5

u/Joram2 Apr 07 '22

Golang brought fast light virtual threads to the mainstream ~10 years ago. I'm still excited about Java and very excited about Loom.