简体   繁体   中英

notify() -> all of the threads in wait set must exit

According to 17.2.4. Interactions of Waits, Notification, and Interruption :

Similarly, notifications cannot be lost due to interrupts. Assume that a set s of threads is in the wait set of an object m, and another thread performs a notify on m. Then either:

a) at least one thread in s must return normally from wait, or

b) all of the threads in s must exit wait by throwing InterruptedException

This surprises me because I know that notify() only wakes up a single thread so b) couldn't happen. The b) option seems to me a completely non-sense because besides implying that notify() is behaving like notifyAll() it's also supposed to interrupt all waiting threads.

Q: is this paragraph wrong? If not then why not?

all of the threads in s must exit wait by throwing InterruptedException

This means all threads waiting on s were interrupted.

b) means that if all threads are interrupted, no thread will wake from wait() normally, due to being interrupted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM