logoalt Hacker News

jayd16yesterday at 8:35 PM1 replyview on HN

They said "Java alternative for green threads" so they're talking about not green threads.


Replies

antonvsyesterday at 9:25 PM

What alternative would they be referring to? Green threads were only (re-)introduced to Java in version 21 in 2023.

I think what they're trying to say is that Java's green thread implementation has special support for async I/O. Threads that block on I/O aren't polled for completion by the runtime, instead they use OS async features under the hood.

This allows Java's green threads to compete performance-wise with async/await solutions, but with cleaner code that doesn't need colored functions.

In older green thread implementations in other languages, I/O can actually cause significant CPU overhead due to polling threads that are blocked by I/O requests.