java-如果线程在wait()上被中断,在到达同步块之外的catch块之前会重新获取监视器吗?
作者:互联网
请考虑以下代码:
try{
synchronized(myLock){
myLock.wait(); // gets interrupted while waiting.
}
}catch(InterruptedException ie){
}
如果线程在wait()上被阻塞时被中断,那么在挂接到catch块之前是否会重新获取myLock的监视器(临时?)?
解决方法:
如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.
因此,是的,它将被阻止,等待重新获取锁,然后引发异常.
标签:multithreading,try-catch,monitor,interrupted-exception,java 来源: https://codeday.me/bug/20191121/2053809.html