Most visited

Recently visited

Added in API level 1

AtomicStampedReference

public class AtomicStampedReference
extends Object

java.lang.Object
   ↳ java.util.concurrent.atomic.AtomicStampedReference<V>


一个 AtomicStampedReference维护一个对象引用以及一个整数“stamp”,可以自动更新。

实现注意事项:此实现通过创建表示“盒装”[引用,整数]对的内部对象来维护标记的引用。

Summary

Public constructors

AtomicStampedReference(V initialRef, int initialStamp)

用给定的初始值创建一个新的 AtomicStampedReference

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

From class java.lang.Object

Public constructors

AtomicStampedReference

Added in API level 1
AtomicStampedReference (V initialRef, 
                int initialStamp)

用给定的初始值创建一个新的 AtomicStampedReference

Parameters
initialRef V: the initial reference
initialStamp int: the initial stamp

Public methods

attemptStamp

Added in API level 1
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

compareAndSet

Added in API level 1
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

get

Added in API level 1
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

getReference

Added in API level 1
V getReference ()

返回参考的当前值。

Returns
V the current value of the reference

getStamp

Added in API level 1
int getStamp ()

返回邮票的当前值。

Returns
int the current value of the stamp

set

Added in API level 1
void set (V newReference, 
                int newStamp)

无条件地设置参考和邮票的价值。

Parameters
newReference V: the new value for the reference
newStamp int: the new value for the stamp

weakCompareAndSet

Added in API level 1
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

Hooray!