AtomicInteger的CAS
public class Test {
/**
* CSA compareAndSet 比较并交换
*
*/
public static void main(String[] args) {
AtomicInteger integer = new AtomicInteger(0);
System.out.println(integer.compareAndSet(0, 1)+" current value: "+integer.get());
System.out.println(integer.compareAndSet(2, 3)+" current value: "+integer.get());
}
}
控制台输出
true current value: 1
false current value: 1