下面的代碼運(yùn)行時不拋異常public?class?Test?extends?Thread?{
public?void?run()?{
try?{
Thread.sleep(1000);
this.interrupt();
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
public?static?void?main(String[]?args)?{
Test?testThread?=?new?Test();
testThread.start();
}
}下面代碼運(yùn)行時拋InterruptedException異常public?class?Test?extends?Thread?{
public?void?run()?{
try?{
Thread.sleep(1000);
this.interrupt();
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
public?static?void?main(String[]?args)?{
Test?testThread?=?new?Test();
testThread.start();
????testThread.interrupt();
}
}照這樣來說:第二段代碼的最后一句 testThread.interrupt(); 這句是main線程調(diào)用的,不是testThread線程調(diào)用的?
添加回答
舉報
0/150
提交
取消