- java.lang.Object
-
- java.util.concurrent.atomic.AtomicStampedReference<V>
-
- 参数类型
-
V- 此引用引用的对象的类型
public class AtomicStampedReference<V> extends Object
一个AtomicStampedReference维护对象引用以及整数“印记”,可以原子更新。实现注意事项:此实现通过创建表示“boxed”[引用,整数]对的内部对象来维护加盖引用。
- 从以下版本开始:
- 1.5
-
-
构造方法摘要
构造方法 Constructor 描述 AtomicStampedReference(V initialRef, int initialStamp)创建一个新的AtomicStampedReference与给定的初始值。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 booleanattemptStamp(V expectedReference, int newStamp)如果当前引用为预期引用的==,则将该戳的值原子设置为给定的更新值。booleancompareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)如果当前引用为预期引用的==,并且当前戳等于预期的戳记,则将引用和戳记的值原子设置为给定的更新值。Vget(int[] stampHolder)返回引用和戳记的当前值。VgetReference()返回引用的当前值。intgetStamp()返回邮票的当前值。voidset(V newReference, int newStamp)无条件地设置引用和戳记的值。booleanweakCompareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)如果当前参考值为预期参考值的==,并且当前印记等于预期的印记,则将引用和标记的值原子设置为给定的更新值。
-
-
-
构造方法详细信息
-
AtomicStampedReference
public AtomicStampedReference(V initialRef, int initialStamp)
创建一个新的AtomicStampedReference与给定的初始值。- 参数
-
initialRef- 初始参考 -
initialStamp- 初始邮票
-
-
方法详细信息
-
getReference
public V getReference()
返回引用的当前值。- 结果
- 当前值的参考
-
getStamp
public int getStamp()
返回邮票的当前值。- 结果
- 邮票的当前值
-
get
public V get(int[] stampHolder)
返回引用和戳记的当前值。 典型用法是int[1] holder; ref = v.get(holder);。- 参数
-
stampHolder- 至少有一个大小的数组。 在退货时,stampHolder[0]将持有该邮票的价值。 - 结果
- 当前值的参考
-
weakCompareAndSet
public boolean weakCompareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)
如果当前引用为期望参考值为==并且当前印记等于预期印记,则将引用和印记的值原子设置为给定的更新值。May fail spuriously and does not provide ordering guarantees ,所以很少适合替代
compareAndSet。- 参数
-
expectedReference- 参考的预期值 -
newReference- 参考的新值 -
expectedStamp- 邮票的预期值 -
newStamp- 邮票的新价值 - 结果
-
true如果成功
-
compareAndSet
public boolean compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)
如果当前引用为预期引用的==,并且当前印记等于预期的印记,则将引用和印记两者的值原子设置为给定的更新值。- 参数
-
expectedReference- 参考的预期值 -
newReference- 参考的新值 -
expectedStamp- 邮票的预期值 -
newStamp- 邮票的新值 - 结果
-
true如果成功
-
set
public void set(V newReference, int newStamp)
无条件地设置引用和戳记的值。- 参数
-
newReference- 参考的新值 -
newStamp- 邮票的新值
-
attemptStamp
public boolean attemptStamp(V expectedReference, int newStamp)
如果当前引用是预期引用的==,则将该戳记的值原子地设置为给定的更新值。 对此操作的任何给定的调用可能会失败(返回false),但是当当前值保持预期值并且没有其他线程也尝试设置该值将最终成功时重复调用。- 参数
-
expectedReference- 参考的预期值 -
newStamp- 邮票的新价值 - 结果
-
true如果成功
-
-