概述 CAS是Compare And Swap的简称,即:比较并交换 Java中常见的是Atomic相关类使用了CAS,例如:AtomicInteger、AtomicBoolean等等 实现CAS的底层用的是Unsafe操作类 先看个小例子 public static void main(String[] args) { AtomicInteger atomicInteger = new AtomicInteger(5); atomicInteger