测试线程退出
package oop.thread;
import java.util.Date;
public class TestInterrupt {
//测试 线程退出的方式一
public static void main(String[] args) {
MyThread thread = new MyThread();
thread.start();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
thread.interrupt();
}
}
class MyThread extends Thread {
@Override
public void run() {
while (true){
System.out.println("===" + new Date() + "====");
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
}
}
}

浙公网安备 33010602011771号