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

昵称:
随便看看
换一批
-
Java 并发编程之 AQS ReentrantLock 非公平锁源码解析阅读 1157
-
MySQL 备份工具 xtrabackup 安装和使用阅读 1321
-
Java 语法糖 - 可变参数阅读 494
-
Spring 事务结束后进行耗时操作阅读 298
-
Tomcat acceptCount 和 maxConnections 参数解析阅读 1133
-
Spring 使用 filter 过滤器、ContentCachingWrapper 包装类获取请求参数和返回值阅读 342
-
设计模式之原型模式 - 深拷贝和浅拷贝阅读 1716
-
OLTP 与 OLAP阅读 3439
-
Chrome 下载提示权限不足阅读 11801
-
Redis 执行 Lua 脚本抛出 StatusOutput does not support set(long) 异常阅读 6610