最近正在看多线程的知识,在实际写代码的时候遇到了一些问题
public class TestStop implements Runnable{
//设置标志位
private boolean flag = true;
@Override
public void run() {
int i = 0;
while(flag){
System.out.println("run....."+i++);
}
}
public void stop(){
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("====="+i);
if (i == 90){
testStop.stop();
System.out.println("stop!!!!!");
}
}
}
}
第一张是把main方法里for循环的输出语句注释掉之后的结果,第二张只是把注释去掉了,我的run方法的信息呢?为什么会出现这么大的区别,我感觉脑子有点糊了,求告一下这是为什么啊。