19、深入理解CAS
19.1. CAS是什么
CAS : CompareAndSwarp ,比较并交换
package com.interview.concurrent.cas;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author yangxj
* @description 描述: compareAndSet 简称 CAS 比较并交换!
* compareAndSet(int expect, int update)
* expect:我期望原来的值是什么,如果是,就更新为update
* @date 2020/2/25 14:46
*/
public class AtomicIntegerDemo {
public static void main(String[] args) {
//参数,初始值设为5
AtomicInteger atomicInteger = new AtomicInteger(5);
System.out.println(atomicInteger.get());