【发布时间】:2013-02-03 21:26:34
【问题描述】:
假设我有以下代码:
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 循环会再次中断吗?
【问题讨论】:
标签: java multithreading concurrency while-loop interrupted-exception