waiting room and monitor lock aq.
Daniel D. Daugherty
daniel.daugherty at oracle.com
Tue Jul 22 16:45:58 UTC 2014
On 7/21/14 4:16 PM, David Holmes wrote:
> On 21/07/2014 10:38 PM, Winnie JayClay wrote:
>> Hi, is there any order between threads which wake up by notifyAll and
>> trying to acquire obj monitor (blocked after synchronized
>> invocation)? Is
>> it mentioned in JLS?
> Ordering is completely unspecified. An implementation is free to do
> what it likes to optimize performance (using whatever metric it chooses).
> So for example a thread that is woken up by a notify/notifyAll and is
> placed into the monitor acquisition queue need not be given preference.
> In general in hotspot the queues are simply FIFO, but the monitor
> implementation also allows barging and monitor release does not
> perform a hand-off.
Filling in some details...
This link: http://docs.oracle.com/javase/specs/index.html
gets you to various versions of the Java Language spec.
This section is probably the one that you want:
17.2. Wait Sets and Notification
Also see Josh Bloch's "Effective Java" book. In particular checkout
the chapter on "Threads" and the item on "Never invoke wait outside
More information about the hotspot-dev