Hacker News new | ask | show | jobs
by Shawnecy 945 days ago
I'm curious as well. Once you can use an ExecutorService with virtual threads, the gap seems a bit thin.

The best I can tell is that coroutines are a bit lighter weight (in terms of what state is managed) and have a bit simpler usage out-of-the-box.

But I've not used them myself so maybe I'm not seeing how big of advantage those are or perhaps there's more to it than that?

2 comments

Well for one, virtual threads would be implicit blocking and this style is explicit.
so kotlin functions are colored while java ones are colorless?
Java doesn't have an equivalent to Kotlin's 'suspend fun'. The CoroutineScope abstraction ('launch', 'join', 'await', etc) is also absent, at least until Structured Concurrency gets released [1] and Java gains StructuredTaskScope.

1: https://openjdk.org/jeps/462

It explicitly says it's not for actual use.

The point (I think) was as an exercise to demonstrate it was possible to implement in 'userland' and how they did so.