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

前端 未结 7 573
被撕碎了的回忆
被撕碎了的回忆 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:32

    This doesn't exactly answer the question, but it will probably solve your problem: Use higher level concurrency mechanisms. Wait/notify is usually more low-level than you'd want, for this reason among many others.

    For example, if you were using BlockingQueue.poll(long, TimeUnit), you could check if the result is null to know if you timed out.

提交回复
热议问题