CAS-两大缺点、AtomicStampedReference入门

1、循环时间长开销很大 

2、ABA问题


版本号时间戳原子引用

AtomicStampedReference带戳记流水的简单演示(单线程) 

@Data
@AllArgsConstructor
@NoArgsConstructor
class Book {
    private int id;
    private String bookName;
}

public class AtomicStampedReferenceDemo {
    public static void main(String[] args) {
        Book javaBook = new Book(1, "javaBook");
        AtomicStampedReference atomicStampedReference = new AtomicStampedReference<>(javaBook, 1);
        System.out.println(atomicStampedReference.getReference() + &

你可能感兴趣的:(JUC并发编程与源码分析,java,开发语言)