Hacker News new | ask | show | jobs
by tomp 696 days ago
Yes, but the problem is that the spec is such that preemptive blocking doesn't need to be implemented.

That means that Java programmers have to be very careful when writing code, lest they block the entire underlying (OS) thread!

Again, Go already went through that experience. It was painful. Java should have learned and implemented it from the start

2 comments

> That means that Java programmers have to be very careful when writing code

From JEP 444:

The scheduler does not currently implement time sharing for virtual threads. Time sharing is the forceful preemption of a thread that has consumed an allotted quantity of CPU time. While time sharing can be effective at reducing the latency of some tasks when there are a relatively small number of platform threads and CPU utilization is at 100%, it is not clear that time sharing would be as effective with a million virtual threads.

Also, in this scenario, i think the current scheduler (ForkJoin Pool) will use managed blocker to compensate those pinned carrier threads.

I don't know. The language already has Thread.Yield. If your use case is such that you have starvation and care about it, it seems trivial to work around.

Still, an annoying gotcha if it hits you unexpectedly.