返回信息流以下截取自java语言规范。第二点提到notify不能被丢失,这点是需要代码去保证的吗,就比如interruptException就再notify一次?
> ### 17.2.4 Interactions of Waits, Notification, and Interruption
The above specifications allow us to determine several properties having to do with the interaction of waits, notification, and interruption.
If a thread is both notified and interrupted while waiting, it may either:
- return normally from wait, while still having a pending interrupt (in other words, a call to Thread.interrupted would return true)
- return from wait by throwing an InterruptedException
> The thread may not reset its interrupt status and return normally from the call to wait.
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:
- at least one thread in s must return normally from wait, or
- all of the threads in s must exit wait by throwing InterruptedException
> Note that if a thread is both interrupted and woken via notify, and that thread returns from wait by throwing an InterruptedException, then some other thread in the wait set must be notified.
这是一条镜像帖。来源:北邮人论坛 / java / #64351同步于 2020/8/28
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
【问题】notify丢失的问题
xuanyu66
2020/8/28镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
欧克克
【 在 nuanyangyang 的大作中提到: 】
: 你就记得在循环里wait,然后定时检查interrupted,是true就自己抛InterruptedException就行了。
: --
: ............