小例子 public class VolatileTest { private static volatile int INIT_VALUE = 0; private final static int MAX_VALUE = 5; public static void main(String[] args) { // 读线程 new Thread(()->{ int localValue = INIT_VALUE; while (localValue < MAX_VALUE){ if (loc…