In the \"Effective Java\", the author mentioned that
while (!done) i++;
can be optimized by HotSpot into
if (!done) {
If you add System.out.println("i = " + i); in the while loop. The hoisting won't work, meaning the program stops as expected. The println method is thread safe so that the jvm can not optimize the code segment?
System.out.println("i = " + i);