package state;
public class TestStop implements Runnable {
private boolean flag = true;
@Override
public void run() {
int i=0;
while (flag){
System.out.println("run.....Thread"+i++);
}
}
public void stop(){
this.flag=false;
}
public static void main(String[] args) {
TestStop thread3 = new TestStop();
new Thread(thread3).start();
for (int i = 0; i <1000 ; i++) {
System.out.println("main"+i);
if (i==900){
thread3.stop();
System.out.println("线程该停止了");
}
}
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-36031.html