atomicInteger原理
class A{ public final static void main(String[] args) { AtomicInteger atomicInteger = new AtomicInteger(); for (int i = 0; i < 10; i++) { atomicInteger.incrementAndGet(); } //atomicInteger.incrementAndGet()的原理,利用CAS原理 while(true){ int expectValue = atomicInteger.get(); int updateValue = expectValue+1; if (atomicInteger.compareAndSet(expectValue,updateValue)){ break; } } int value = atomicInteger.get(); } }