Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: typeau

...

The notify() and notifyAll() methods of package java.lang.Object are used to wake up waiting thread(s). These methods must be invoked from a thread that holds the same object lock as the waiting thread(s); these methods throw an IllegalMonitorStateException when invoked from any other thread. The notifyAll() method wakes up all threads associated with an object lock and allows threads whose condition predicate is true to resume execution. Furthermore, if all the threads whose condition predicate evaluates to true previously held a specific lock before going into the wait state, only one of them will reacquire the lock upon being notified. Presumably, the other threads will resume waiting. The notify() method wakes up only one thread, and any guarantee regarding which specific thread is notified. The chosen thread is permitted to resume waiting if its condition predicate is unsatisfied; this often defeats the purpose of the notification.

Consequently, the invoking the notify() method is permitted only when all of the following conditions are met:

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="198118cc7ee7a7c5-ff70a2f4-4d0441f6-a0cc943b-b34f82d599cddfb0a79b8301"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

java.util.concurrent.locks.Condition interface

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a819526c5542542e-feb2db4a-465f4a67-b309b10f-8c723a837a3216d7bdf5599a"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

[Chapter 17, Threads and Locks

http://java.sun.com/docs/books/jls/third_edition/html/memory.html]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a8a2ba3e4b3ea19b-b20c209a-426449f0-bb748224-1680082c283ee1549e387ecc"><ac:plain-text-body><![CDATA[

[[Goetz 2006

AA. Bibliography#Goetz 06]]

Section 14.2.4, Notification

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="87164a743678f273-4037ea53-46594a05-9ebcb682-cca3bba1f3990d5f910f67e0"><ac:plain-text-body><![CDATA[

[[Bloch 2001

AA. Bibliography#Bloch 01]]

Item 50: Never invoke wait outside a loop

]]></ac:plain-text-body></ac:structured-macro>

...