Re:Java 21 Released
by 5e92cb50239222b on Tuesday September 19, 2023 @11:57AM
(#37571844)
You're supposed to either await a Task, or to block on it (thus blocking the underlying OS thread which probably eats a couple of megabytes of RAM). It's a completely different system more akin to what Go has been using.
[ Parent
| on HN ]
Re:Java 21 Released
by neonsunset on Tuesday September 19, 2023 @05:55PM
(#37577407)
This is not necessarily correct. Tasks can be run in a "fire-and-forget" way. Also, only synchronous prelude of the task is executed inline in .NET.
The continuation will then be ran on threadpool worker thread (unless you override task scheduler and continuation context).
Also, you can create multiple tasks in a method and then await their results later down the execution path when you actually need it, easily achieving concurrency.
Green threads is a more limited solution focused first and foremost on solving blocking.
But there is no point to it in this comparison if it can block a whole thread to itself - that can be done with java as well since forever.
Re:Java 21 Released
by neonsunset on Tuesday September 19, 2023 @06:43PM
(#37578069)
Blocking the thread with unawaited task.Result is an explicit choice which will be flagged by a warning by an IDE and when building, that this may not be what you intended.