r/java • • Jun 10 '24

[deleted by user]

[removed]

618 Upvotes

594 comments sorted by

View all comments

Show parent comment

2

u/maumay Jun 10 '24

I believe Goroutines are comparable to virtual threads in that m goroutines are mapped onto n platform threads where the runtime handles the scheduling.

2

u/vprise Jun 11 '24

It doesn't according to this: https://stackoverflow.com/a/24599790/756809

It opens a new thread when blocked which is a very different thing. Virtual threads use the extra CPU cores even when they aren't blocked. That means you get 100% of the capabilities of the hardware from the start and use sophisticated capabilities soon after.

Also "blocked" does some pretty heavy lifting in that definition. Java has the advantage of the JVM which includes both the execution runtime and the libraries. Handling asynchronous cases is something that Java can handle seamlessly without laying the complexity on the developer. That means better scheduling logic and fewer developer errors.