V
-对象的类型称为参考
public class AtomicStampedReference<V> extends Object
AtomicStampedReference
保持随着整数“邮票”一个对象的引用,可以自动更新。
实现说明:此实现通过创建表示“框”[参考,整数]对的内部对象来保持标记的引用。
Constructor and Description |
---|
AtomicStampedReference(V initialRef, int initialStamp)
创建具有给定的初始值的一个新的
AtomicStampedReference 。
|
Modifier and Type | Method and Description |
---|---|
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)
自动设置的参考和印花的更新值,如果电流参考
== 预计参考目前印花等于预期的邮票。
|
public AtomicStampedReference(V initialRef, int initialStamp)
AtomicStampedReference
。
initialRef
-初始参考
initialStamp
-最初的邮票
public V getReference()
public int getStamp()
public V get(int[] stampHolder)
int[1] holder; ref = v.get(holder);
。
stampHolder
-至少一个大小的数组。返回时,
stampholder[0]
将邮票的价值。
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
如果成功
public boolean compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)
==
预计参考目前印花等于预期的邮票。
expectedReference
-参考期望值
newReference
为参考的新价值
expectedStamp
-邮票的期望值
newStamp
-印花的新价值
true
如果成功
public void set(V newReference, int newStamp)
newReference
为参考的新价值
newStamp
-印花的新价值
public boolean attemptStamp(V expectedReference, int newStamp)
==
到预期的参考。任何给定的操作调用可能失败(返回
false
)不合逻辑,但反复调用时,当前值是期望值和没有其他线程也试图设置值将最终取得成功。
expectedReference
-参考期望值
newStamp
-印花的新价值
true
如果成功
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.