Expansion of native thread count by Object.wait() vs Condition.await()

Alan Bateman Alan.Bateman at oracle.com
Mon Oct 9 17:29:12 UTC 2023

On 09/10/2023 18:05, Anton Vodonosov wrote:
> Hello.
> The JEP 444 text says that for Object.wait(), the virtual thread remains
>   mounted while blocked, but the scheduler will compensate for that by
> temporarily adding a native thread to its ForJoinPool.
> But for BlockingQueue.take() the blocked virtual thread not only
> remains mounted (and pinned) to the native thread, but also
> the scheduler does not compensate for that.
> BlockingQueue.take() is implemented using Condition.await().
> Object.wait() and Condition.await() are so similar in their semantics.
> Is JEP 444 text correct that one is compensated by a temporary
> native thread and another is not?
The JEP text is correct, Object.wait does compensate, parking while 
holding a monitor doesn't (Condition.await is one case of parking).

We know pinning is a pain point. There are efforts under way to improve 
things, in particular for the case where a virtual thread parks while 
holding a monitor.


More information about the loom-dev mailing list