测试线程退出

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;
}
}
}
}
posted @ 2021-01-30 22:41  __sunshine  阅读(18)  评论(0)    收藏  举报