Hacker News new | ask | show | jobs
by jeremyjh 1506 days ago
> How does it know that an operation is blocking on I/O? Is this limited to stuff baked into the language or standard library?

Most libraries use the I/O primitives from the platform standard libraries, so the behaviour is going to trickle out from there. If you aren't using those libraries, the only other way to do I/O would be to use native code such as via JNI, and the runtime would schedule that on a thread pool and so it would tie up an OS thread for the duration of a function invocation.

1 comments

thanks, this explains the mysterious magic that I think is probably bugging a lot of people.

It will be interesting to see how much of a coloring problem this creates, if any. I guess the great thing about having it be standardised and baked into the language / VM is it will quickly become de facto best practice to make any such library code compliant with virtual threads. And for all its various downsides, the java ecosystem has always leaned away from native code and treated it as a last resort rather than leaning into it like Python etc. So likely it will not be a huge issue the way the coloring problem is in the async/await situation.

As a preparation, some parts of the standard library indeed had to be rewritten in pure Java to be compatible with Loom, for example the socket implementations.

https://openjdk.java.net/jeps/373

http://openjdk.java.net/jeps/353

Yes in other languages with this baked into the platform - such as Haskell, Go and Erlang - it just works and there is no color problem.