| |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
java.util.concurrent.atomic
类 AtomicStampedReference<V>
java.lang.Object java.util.concurrent.atomic.AtomicStampedReference<V>
- 类型参数:
V
- 此引用所引用的对象类型。
public class AtomicStampedReference<V>
- extends Object
AtomicStampedReference 维护带有整数“标志”的对象引用,可以原子方式对其进行更新。
实现注意事项。通过创建表示“已装箱”的 [reference, integer] 对的内部对象,此实现维持带标志的引用。
- 从以下版本开始:
- 1.5
构造方法摘要 | |
---|---|
AtomicStampedReference(V initialRef, int initialStamp) 使用给定的初始值创建新的 AtomicStampedReference。 |
方法摘要 | |
---|---|
boolean | attemptStamp(V expectedReference, int newStamp) 如果当前引用 == 预期引用,则以原子方式将该标志的值设置为给定的更新值。 |
boolean | compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp) 如果当前引用 == 预期引用,并且当前标志等于预期标志,则以原子方式将该引用和该标志的值设置为给定的更新值。 |
V | get(int[] stampHolder) 返回该引用和该标志的当前值。 |
V | getReference() 返回该引用的当前值。 |
int | getStamp() 返回该标志的当前值。 |
void | set(V newReference, int newStamp) 无条件地同时设置该引用和标志的值。 |
boolean | weakCompareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp) 如果当前引用 == 预期引用,并且当前标志等于预期标志,则以原子方式将该引用和该标志的值设置为给定的更新值。 |
从类 java.lang.Object 继承的方法 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
构造方法详细信息 |
---|
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
- 大小至少为 1 的数组。返回时,stampholder[0] 将保存该标志的值。- 返回:
- 该引用的当前值
weakCompareAndSet
public boolean weakCompareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)
- 如果当前引用 == 预期引用,并且当前标志等于预期标志,则以原子方式将该引用和该标志的值设置为给定的更新值。此操作的任何给定调用都可能会意外失败(返回 false),但是在当前值保持预期值而且没有其他线程也在尝试设置该值时,重复调用将最终获得成功。
- 参数:
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