import java.util.*;
public class TestInterrupt {
public static void main(String args[]){
MyThread thread = new MyThread();
thread.start();
try {
thread.sleep(10000);
}catch (InterruptedException e){}
thread.interrupt();
}
}
class MyThread extends Thread{//第二种创造线程;
boolean flag = true;
public void run(){
while (flag){
System.out.println("==="+new Date()+"===");
try {
sleep(1000);
}catch (InterruptedException e){
flag = false;
}
}
}
}
java多线程Interrupt中断线程
最新推荐文章于 2024-10-08 14:23:59 发布