请考虑以下代码:
try{
synchronized(myLock){
myLock.wait(); // gets interrupted while waiting.
}
}catch(InterruptedException ie){
}
如果线程在 wait() 阻塞时被中断,myLock 的监视器是否会在进入 catch block 之前重新获取(暂时?)?
最佳答案
作为javadoc州
If the current thread is interrupted by any thread before or while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
所以,是的,它会阻塞等待重新获取锁,然后抛出异常。
关于java - 如果线程在 wait() 上被中断,是否会在到达同步块(synchronized block)之外的 catch block 之前重新获取监视器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23797852/