Java JIT compiler optimizations - is JIT consistent in respect to volatile variables value caching?
问题 I'm trying to better understand how does the JIT compiler work for java in respect to volatile variable value caching. Consider the example presented in this question: Infinite loop problem with while loop and threading: boolean loaded = false; // not volatile!!! private boolean loadAsset() { new Thread(new Runnable() { @Override public void run() { // Do something loaded = true; } }).start(); while (!loaded) { System.out.println("Not Loaded"); } System.out.println("Loaded"); return false; }