/* * This class intended to be implemented using VarHandles, but there * are unresolved cyclic startup dependencies. */ privatestaticfinal jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe(); privatestaticfinallong VALUE = U.objectFieldOffset(AtomicInteger.class, "value");
privatevolatileint value;
volatile 修饰,保证 value 是可见的,当某个线程修改 value 值时,对其他线程可见,其他线程访问时就不会通过缓存去取,而是到内存中取,保证 value 的一致性。