CAS的理解
public final int incrementAndGet() {
for (;;) {//一直循环
int current = get();//取出AtomicInteger当前的内存值
int next = current + 1;//要设置的新值
if (compareAndSet(current, next)){//用CAS操作更新AtomicInteger
return next;
}
}
}内容来源
Last updated