Yesterday , I wrote some code like this:
public class WhileTest {
private static boolean close=false;
public static void main(String[] args) throws InterruptedException {
new Thread(new Runnable() {
@Override
public void run() {
while(true) {
int i=0;
while(!close) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("count:"+i++);
}
}
}
}).start();
System.out.println("close:"+close);
Thread.sleep(3000);
close=true;
System.out.println("close:"+close);
Thread.sleep(3000);
close=false;
System.out.println("close:"+close);
Thread.sleep(3000);
close=true;
System.out.println("close:"+close);
System.exit(0);
}}
when close set to false again, it was not print count anymore,I run javap to see if !close condition in while loop was compiled to true,and it's not ,I don't understand,can anyone help me ?