0
假设我有一个线程类是这样的:中断的线程是否会继续其事务?
public class ThreadClass extends Thread{
Object object = new Object(); //relevant object
public void run(){
synchronized(object){
if(/*condition is true*/){
//do transactions here
}else{
try{
object.wait();
}catch(InterruptedException e){
//if thread was interrupted
}
}
//other transactions here
}
}
}
如果当前线程被中断,它会继续交易?是否还会去其他交易?谢谢。
通过一个调试器运行代码......当你逐步浏览它时,你会注意到它继续其事务,因为'InterruptedException'被捕获并被有效地“吞噬”,但是如果在此之后发出另一个中断在其他交易中,它会杀死线程。 – mre