package com.prj;
public class TestStop implements Runnable {
private boolean flag=true;
public void run() {
// TODO Auto-generated method stub
int i=0;
while(flag) {
System.out.println("run..thread "+i++);
}
}
public void stop() {
// TODO Auto-generated method stub
this.flag=false;
}
public static void main(String[] args) {
TestStop teststop=new TestStop();
new Thread(teststop).start();
for (int i = 0; i < 100; i++) {
System.out.println("main "+i);
if(i==90) {
teststop.stop();
System.out.println("线程应该停止了");
}
}
}
}