public class AtomicStampedReference
extends Object
| java.lang.Object | |
| java.util.concurrent.atomic.AtomicStampedReference<V> | |
一个 AtomicStampedReference维护一个对象引用以及一个整数“stamp”,可以自动更新。
实现注意事项:此实现通过创建表示“盒装”[引用,整数]对的内部对象来维护标记的引用。
Public constructors |
|
|---|---|
AtomicStampedReference(V initialRef, int initialStamp) 用给定的初始值创建一个新的 |
|
公共方法(Public methods) |
|
|---|---|
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) 如果当前参考值为预期参考值的 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
AtomicStampedReference (V initialRef,
int initialStamp)
用给定的初始值创建一个新的 AtomicStampedReference 。
| 参数(Parameters) | |
|---|---|
initialRef |
V: the initial reference |
initialStamp |
int: the initial stamp |
boolean attemptStamp (V expectedReference,
int newStamp)
如果当前参考值为预期参考值的== ,则将==值设置为给定更新值。 任何给定的此操作调用可能会失败(返回false ),但当当前值保持期望值并且没有其他线程也试图设置该值时重复调用将最终成功。
| 参数(Parameters) | |
|---|---|
expectedReference |
V: the expected value of the reference |
newStamp |
int: the new value for the stamp |
| 返回(Returns) | |
|---|---|
boolean |
true if successful |
boolean compareAndSet (V expectedReference,
V newReference,
int expectedStamp,
int newStamp)
如果当前参考值为预期参考值的 == ,并且当前标记等于预期标记,则以原子方式将参考值和标记的值设置为给定更新值。
| 参数(Parameters) | |
|---|---|
expectedReference |
V: the expected value of the reference |
newReference |
V: the new value for the reference |
expectedStamp |
int: the expected value of the stamp |
newStamp |
int: the new value for the stamp |
| 返回(Returns) | |
|---|---|
boolean |
true if successful |
V get (int[] stampHolder)
返回参考和印章的当前值。 典型用法是int[1] holder; ref = v.get(holder); 。
| 参数(Parameters) | |
|---|---|
stampHolder |
int: an array of size of at least one. On return, stampHolder[0] will hold the value of the stamp. |
| 返回(Returns) | |
|---|---|
V |
the current value of the reference |
V getReference ()
返回参考的当前值。
| 返回(Returns) | |
|---|---|
V |
the current value of the reference |
int getStamp ()
返回邮票的当前值。
| 返回(Returns) | |
|---|---|
int |
the current value of the stamp |
void set (V newReference,
int newStamp)
无条件地设置参考和邮票的价值。
| 参数(Parameters) | |
|---|---|
newReference |
V: the new value for the reference |
newStamp |
int: the new value for the stamp |
boolean weakCompareAndSet (V expectedReference,
V newReference,
int expectedStamp,
int newStamp)
如果当前参考值为预期参考值的 == ,并且当前标记等于预期标记,则以原子方式将参考值和标记的值设置为给定更新值。
May fail spuriously and does not provide ordering guarantees ,所以很少是 compareAndSet的合适替代 compareAndSet 。
| 参数(Parameters) | |
|---|---|
expectedReference |
V: the expected value of the reference |
newReference |
V: the new value for the reference |
expectedStamp |
int: the expected value of the stamp |
newStamp |
int: the new value for the stamp |
| 返回(Returns) | |
|---|---|
boolean |
true if successful |