Java 并发编程之 AtomicBoolean
Java juc 大约 560 字代码
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));
}
阅读 435 · 发布于 2021-09-20
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
k3s 设置镜像阅读 235
-
GoJS 更改 Overview 的拖动框颜色阅读 413
-
PostgreSQL 备份与还原阅读 3492
-
PostgreSQL 重置序列序号阅读 829
-
设计模式之桥接模式阅读 1566
-
Windows WSL 下 Docker 启动报 waiting for init preliminary setup caused: EOF: unknown 错误阅读 1151
-
MySQL 聚集索引和非聚集索引阅读 780
-
OpenResty 中使用 ngx.location.capture 完成第三方接口请求阅读 6029
-
Charles 提示 SSL Proxying not enabled for this host阅读 7305
-
Redis 运行统计信息阅读 1338