package xiancheng;
public class ThreadLife {
public static void main(String[] args) {
TestThread1 t = new TestThread1();
new Thread(t).start();
for(int i=0;i<10;i++){
if(i==5)
t.stopMe();
System.out.println("Main线程在运行");
}
}
}
class TestThread1 implements Runnable{
private boolean bFlag = true;
public void stopMe(){
bFlag = false;
}
public void run(){
while(bFlag){
System.out.println(Thread.currentThread().getName()+"在运行-------");
}
}
}
线程生命周期的控制
最新推荐文章于 2020-12-18 13:28:55 发布