Java 并发编程之 AtomicBoolean
Java juc About 560 words代码
public class AtomicBooleanDemo {
public static void main(String[] args) {
AtomicBoolean atomicBoolean = new AtomicBoolean();
boolean b = atomicBoolean.get();
atomicBoolean.compareAndSet(b, true);
}
}
源码解析
AtomicBoolean
底层是使用int
类型字段,用1
表示true
,0
表示false
。
compareAndSet
底层源码。
private volatile int value;
public final boolean compareAndSet(boolean expectedValue, boolean newValue) {
return VALUE.compareAndSet(this,
(expectedValue ? 1 : 0),
(newValue ? 1 : 0));
}
Views: 1,662 · Posted: 2021-09-20
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...