public class TestInterrupt {
public static void main(String[] args) {
MyThread thread = new MyThread();
thread.start();
try {
Thread.sleep(5000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
thread.interrupt();
}
}
class MyThread extends Thread {
boolean flag = true;
public void run(){
try {
sleep(10000);
} catch (InterruptedException e) {
System.out.println("hahahahaha");
}
}
}
主線程休眠5秒後interrupt正在休眠的子線程!interrupt後為什麼程式就結束了呢?和前一篇沖突了?