import java.util.*;
public class TestInterrupt {
public static void main(String[] args) {
SubThread subt = new SubThread();
Thread thr = new Thread(subt);
thr.start();
try{
Thread.sleep(10000);
}catch(InterruptedException interrupt){
}
subt.flag = false;
}
}
class SubThread implements Runnable{
boolean flag = true;
public void run(){
while(flag){
System.out.println("====" + new Date() + "====");
try{
Thread.currentThread();
Thread.sleep(1000);
}catch(InterruptedException interrupt){
return;
}
}
}
}
線程玩具:打斷(interrupted)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.