java.lang.Object
java.util.concurrent.atomic.AtomicReference<V>
- 类型参数:
V- 此引用引用的对象类型
- 所有已实现的接口:
Serializable
可以自动更新的对象引用。有关原子访问属性的描述,请参阅
VarHandle 规范。
- 自从:
- 1.5
- 参见:
-
构造方法总结
构造方法构造方法描述创建一个初始值为 null 的新 AtomicReference。AtomicReference(V initialValue) 使用给定的初始值创建一个新的 AtomicReference。 -
方法总结
修饰符和类型方法描述final VaccumulateAndGet(V x, BinaryOperator<V> accumulatorFunction) 以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值以及将给定函数应用于当前值和给定值的结果,并返回更新后的值。final VcompareAndExchange(V expectedValue, V newValue) 如果当前值称为 witness value、== expectedValue,具有VarHandle.compareAndExchange(java.lang.Object...)指定的记忆效应,则原子地将值设置为newValue。final VcompareAndExchangeAcquire(V expectedValue, V newValue) 如果当前值称为 witness value、== expectedValue,具有VarHandle.compareAndExchangeAcquire(java.lang.Object...)指定的记忆效应,则原子地将值设置为newValue。final VcompareAndExchangeRelease(V expectedValue, V newValue) 如果当前值称为 witness value、== expectedValue,具有VarHandle.compareAndExchangeRelease(java.lang.Object...)指定的记忆效应,则原子地将值设置为newValue。final booleancompareAndSet(V expectedValue, V newValue) 如果当前值为== expectedValue,则以原子方式将值设置为newValue,并具有由VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应。final Vget()返回当前值,具有VarHandle.getVolatile(java.lang.Object...)指定的记忆效应。final V返回当前值,具有VarHandle.getAcquire(java.lang.Object...)指定的记忆效应。final VgetAndAccumulate(V x, BinaryOperator<V> accumulatorFunction) 以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值以及将给定函数应用于当前值和给定值的结果,并返回先前的值。final V以原子方式将值设置为newValue并返回旧值,具有VarHandle.getAndSet(java.lang.Object...)指定的记忆效应。final VgetAndUpdate(UnaryOperator<V> updateFunction) 以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值与应用给定函数的结果,返回先前的值。final V返回当前值,具有VarHandle.getOpaque(java.lang.Object...)指定的记忆效应。final VgetPlain()返回当前值,具有读取的内存语义,就好像变量被声明为 non-volatile一样。final void将值设置为newValue,具有VarHandle.setRelease(java.lang.Object...)指定的记忆效应。final void将值设置为newValue,具有VarHandle.setVolatile(java.lang.Object...)指定的记忆效应。final void将值设置为newValue,具有VarHandle.setOpaque(java.lang.Object...)指定的记忆效应。final void将值设置为newValue,设置的内存语义就好像变量被声明为 non-volatile和 non-final一样。final voidsetRelease(V newValue) 将值设置为newValue,具有VarHandle.setRelease(java.lang.Object...)指定的记忆效应。toString()返回当前值的字符串表示形式。final VupdateAndGet(UnaryOperator<V> updateFunction) 使用给定函数的应用结果以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值,返回更新后的值。final booleanweakCompareAndSet(V expectedValue, V newValue) 已弃用。final booleanweakCompareAndSetAcquire(V expectedValue, V newValue) 如果当前值为== expectedValue,则可能自动将该值设置为newValue,具有由VarHandle.weakCompareAndSetAcquire(java.lang.Object...)指定的记忆效应。final booleanweakCompareAndSetPlain(V expectedValue, V newValue) 如果当前值为== expectedValue,则可能自动将该值设置为newValue,并具有由VarHandle.weakCompareAndSetPlain(java.lang.Object...)指定的记忆效应。final booleanweakCompareAndSetRelease(V expectedValue, V newValue) 如果当前值为== expectedValue,则可能自动将该值设置为newValue,并具有由VarHandle.weakCompareAndSetRelease(java.lang.Object...)指定的记忆效应。final booleanweakCompareAndSetVolatile(V expectedValue, V newValue) 如果当前值为== expectedValue,则可能自动将该值设置为newValue,并具有由VarHandle.weakCompareAndSet(java.lang.Object...)指定的记忆效应。
-
构造方法详细信息
-
AtomicReference
使用给定的初始值创建一个新的 AtomicReference。- 参数:
initialValue- 初始值
-
AtomicReference
public AtomicReference()创建一个初始值为 null 的新 AtomicReference。
-
-
方法详情
-
get
返回当前值,具有VarHandle.getVolatile(java.lang.Object...)指定的记忆效应。- 返回:
- 当前值
-
set
将值设置为newValue,具有VarHandle.setVolatile(java.lang.Object...)指定的记忆效应。- 参数:
newValue- 新值
-
lazySet
将值设置为newValue,具有VarHandle.setRelease(java.lang.Object...)指定的记忆效应。- 参数:
newValue- 新值- 自从:
- 1.6
-
compareAndSet
如果当前值为== expectedValue,则以原子方式将值设置为newValue,并具有由VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
true如果成功。错误返回表示实际值不等于预期值。
-
weakCompareAndSet
已弃用。此方法具有普通记忆效应,但方法名称暗示易失性记忆效应(请参阅compareAndExchange(V, V)和compareAndSet(V, V)等方法)。为避免混淆普通或易失性记忆效应,建议改用方法weakCompareAndSetPlain(V, V)。如果当前值为== expectedValue,则可能自动将该值设置为newValue,并具有由VarHandle.weakCompareAndSetPlain(java.lang.Object...)指定的记忆效应。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
true如果成功- 参见:
-
weakCompareAndSetPlain
如果当前值为== expectedValue,则可能自动将该值设置为newValue,并具有由VarHandle.weakCompareAndSetPlain(java.lang.Object...)指定的记忆效应。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
true如果成功- 自从:
- 9
-
getAndSet
以原子方式将值设置为newValue并返回旧值,具有VarHandle.getAndSet(java.lang.Object...)指定的记忆效应。- 参数:
newValue- 新值- 返回:
- 以前的值
-
getAndUpdate
以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值与应用给定函数的结果,返回先前的值。该函数应该是无副作用的,因为当由于线程之间的争用而尝试更新失败时,它可能会被重新应用。- 参数:
updateFunction- 无副作用的函数- 返回:
- 以前的值
- 自从:
- 1.8
-
updateAndGet
使用给定函数的应用结果以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值,返回更新后的值。该函数应该是无副作用的,因为当由于线程之间的争用而尝试更新失败时,它可能会被重新应用。- 参数:
updateFunction- 无副作用的函数- 返回:
- 更新值
- 自从:
- 1.8
-
getAndAccumulate
以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值以及将给定函数应用于当前值和给定值的结果,并返回先前的值。该函数应该是无副作用的,因为当由于线程之间的争用而尝试更新失败时,它可能会被重新应用。该函数应用当前值作为其第一个参数,给定的更新作为第二个参数。- 参数:
x- 更新值accumulatorFunction- 两个参数的无副作用函数- 返回:
- 以前的值
- 自从:
- 1.8
-
accumulateAndGet
以原子方式更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应)当前值以及将给定函数应用于当前值和给定值的结果,并返回更新后的值。该函数应该是无副作用的,因为当由于线程之间的争用而尝试更新失败时,它可能会被重新应用。该函数应用当前值作为其第一个参数,给定的更新作为第二个参数。- 参数:
x- 更新值accumulatorFunction- 两个参数的无副作用函数- 返回:
- 更新值
- 自从:
- 1.8
-
toString
返回当前值的字符串表示形式。 -
getPlain
返回当前值,具有读取的内存语义,就好像变量被声明为 non-volatile一样。- 返回:
- 值
- 自从:
- 9
-
setPlain
将值设置为newValue,设置的内存语义就好像变量被声明为 non-volatile和 non-final一样。- 参数:
newValue- 新值- 自从:
- 9
-
getOpaque
返回当前值,具有VarHandle.getOpaque(java.lang.Object...)指定的记忆效应。- 返回:
- 值
- 自从:
- 9
-
setOpaque
将值设置为newValue,具有VarHandle.setOpaque(java.lang.Object...)指定的记忆效应。- 参数:
newValue- 新值- 自从:
- 9
-
getAcquire
返回当前值,具有VarHandle.getAcquire(java.lang.Object...)指定的记忆效应。- 返回:
- 值
- 自从:
- 9
-
setRelease
将值设置为newValue,具有VarHandle.setRelease(java.lang.Object...)指定的记忆效应。- 参数:
newValue- 新值- 自从:
- 9
-
compareAndExchange
如果当前值称为 witness value、== expectedValue,具有VarHandle.compareAndExchange(java.lang.Object...)指定的记忆效应,则原子地将值设置为newValue。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
- 见证值,如果成功,它将与预期值相同
- 自从:
- 9
-
compareAndExchangeAcquire
如果当前值称为 witness value、== expectedValue,具有VarHandle.compareAndExchangeAcquire(java.lang.Object...)指定的记忆效应,则原子地将值设置为newValue。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
- 见证值,如果成功,它将与预期值相同
- 自从:
- 9
-
compareAndExchangeRelease
如果当前值称为 witness value、== expectedValue,具有VarHandle.compareAndExchangeRelease(java.lang.Object...)指定的记忆效应,则原子地将值设置为newValue。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
- 见证值,如果成功,它将与预期值相同
- 自从:
- 9
-
weakCompareAndSetVolatile
如果当前值为== expectedValue,则可能自动将该值设置为newValue,并具有由VarHandle.weakCompareAndSet(java.lang.Object...)指定的记忆效应。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
true如果成功- 自从:
- 9
-
weakCompareAndSetAcquire
如果当前值为== expectedValue,则可能自动将该值设置为newValue,具有由VarHandle.weakCompareAndSetAcquire(java.lang.Object...)指定的记忆效应。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
true如果成功- 自从:
- 9
-
weakCompareAndSetRelease
如果当前值为== expectedValue,则可能自动将该值设置为newValue,并具有由VarHandle.weakCompareAndSetRelease(java.lang.Object...)指定的记忆效应。- 参数:
expectedValue- 期望值newValue- 新值- 返回:
true如果成功- 自从:
- 9
-
compareAndExchange(V, V)和compareAndSet(V, V)等方法)。