有这个等待声明:
public final native void wait(long timeout) throws InterruptedException;
它可能会因 InterruptedException 或超时而退出,或者因为在另一个线程中调用了 Notify/NotifyAll 方法,异常很容易捕获但是......
有什么方法可以知道退出原因是超时还是通知?
编辑:
这是一种可行的棘手方法,(尽管我不喜欢它)
long tBefore=System.currentTimeMillis();
wait(TIMEOUT);
if ((System.currentTimeMillis() - tBefore) > TIMEOUT)
{
//timeout
}