package BufferedTest;
?
public class TestStop1 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) {
?
TestStop1 s1 = new TestStop1();
?
new Thread(s1).start();
?
for (int i = 0; i < 1000; i++) {
?
System.out.println("main"+i);
if(i == 900){
s1.stop();
System.out.println("线程该停止了");
}
}
?
}
}
原文:https://www.cnblogs.com/java5745/p/15227918.html