下面的代码运行时不抛异常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();
}
}下面代码运行时抛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线程调用的,不是testThread线程调用的?
添加回答
举报
0/150
提交
取消