摘要
CAS就是比较交换算法。
基本类型
AtomicBoolean - 布尔类型原子类
AtomicInteger - 整型原子类
AtomicLong - 长整型原子类
引用类型
AtomicReference - 引用类型原子类
AtomicMarkableReference - 带有标记位的引用类型原子类
AtomicStampedReference - 带有版本号的引用类型原子类
数组类型
AtomicIntegerArray - 整形数组原子类
AtomicLongArray - 长整型数组原子类
AtomicReferenceArray - 引用类型数组原子类
属性更新器类型
AtomicIntegerFieldUpdater - 整型字段的原子更新器。
AtomicLongFieldUpdater - 长整型字段的原子更新器。
AtomicReferenceFieldUpdater - 原子更新引用类型里的字段。
CAS底层原理
核心思想是unsafe类+CAS自旋锁的实现来保证CPU源语来保证原子性。
UnSafe类
CAS的优缺点
ABA问题
原子引用更新
如何解决ABA问题
采用的是原子引用+时间戳(版本号)
博文参考
全面了解 Java 原子变量类 - 静默虚空 - 博客园
https://www.youtube.com/watch?v=65b3T9mgkOM&list=PLmOn9nNkQxJGEztWTgs2r-ihSAQtcgaCi&index=18
