LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 184|回复: 0

Atomic: 原子类

[复制链接]
发表于 2024-1-16 15:45:40 | 显示全部楼层 |阅读模式
Atomic: 原子类
其基本的特性就是在多线程环境下,当有多个线程同时执行这些类的实例包含的方法时,具有排他性,即当某个线程进入方法,执行其中的指令时,不会被其他线程打断,而别的线程就像自旋锁一样,一直等到该方法执行完成,才由JVM从等待队列中选择一个另一个线程进入,这只是一种逻辑上的理解。实际上是借助硬件的相关指令来实现的,不会阻塞线程(或者说只是在硬件级别上阻塞了)。
对CAS,Unsafe类,以及13个原子类详解请参考:详细分析请看: JUC原子类: CAS, Unsafe和原子类详解
# 基础类型:AtomicBoolean,AtomicInteger,AtomicLong
AtomicBoolean,AtomicInteger,AtomicLong是类似的,分别针对bool,interger,long的原子类。
# 数组:AtomicIntegerArray,AtomicLongArray,BooleanArray
AtomicIntegerArray,AtomicLongArray,AtomicBooleanArray是数组原子类。
# 引用:AtomicReference,AtomicMarkedReference,AtomicStampedReference
AtomicReference,AtomicMarkedReference,AtomicStampedReference是引用相关的原子类。
# FieldUpdater:AtomicLongFieldUpdater,AtomicIntegerFieldUpdater,AtomicReferenceFieldUpdater
AtomicLongFieldUpdater,AtomicIntegerFieldUpdater,AtomicReferenceFieldUpdater是FieldUpdater原子类。
原文链接:https://pdai.tech/md/java/thread/java-thread-x-juc-overview.html

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表