How to differentiate when wait(long timeout) exit for notify or timeout?

前端 未结 7 581
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 02:58

Having this wait declaration:

public final native void wait(long timeout) throws InterruptedException;

It could exit by InterruptedExceptio

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 03:30

    You can't differentiate between the two unless you provide some additional code. For example by adding a ThreadLocal Boolean that is set to true only on notify()

    But first you must make sure your logic requires this differentiation.

提交回复
热议问题