下面的代码运行时不抛异常
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线程调用的?
半枯
相关分类