假设我有以下代码:
while(!Thread.currentThread().isInterrupted()){
//do something
Thread.sleep(5000);
}
现在Thread.sleep
抛出 `InterruptedException 所以它应该是这样的:
while(!Thread.currentThread().isInterrupted()){
//do something
try{
Thread.sleep(5000);
} catch(InterruptedException e){
}
}
如果我点击循环catch
会while
继续还是我需要这样做Thread.currentThread().interrupt()
?如果我确实调用此方法,那是否也会导致InterruptedException
?否则我一开始是怎么得到异常的?
另外,如果我有:
while (!Thread.currentThread().isInterrupted()){
//do something
callMethod();
}
private void callMethod(){
//do something
try {
Thread.sleep(5000);
} catch(InterruptedException e){
}
}
我的while
循环会再次中断吗?