public class AtomicMarkableReference 
 extends Object 
| java.lang.Object | |
| ↳ | java.util.concurrent.atomic.AtomicMarkableReference<V> | 
一个 AtomicMarkableReference维护一个对象引用以及一个标记位,可以自动更新。
实现注意事项:该实现通过创建表示“盒装”[引用,布尔]对的内部对象来维护可标记的引用。
| Public constructors | |
|---|---|
|  AtomicMarkableReference(V initialRef, boolean initialMark) 用给定的初始值创建一个新的  | |
| Public methods | |
|---|---|
|  boolean |  attemptMark(V expectedReference, boolean newMark) 如果当前参考值为预期参考值的  | 
|  boolean |  compareAndSet(V expectedReference, V newReference, boolean expectedMark, boolean newMark) 如果当前参考值为预期参考值的  | 
|  V |  get(boolean[] markHolder) 返回参考和标记的当前值。 | 
|  V |  getReference() 返回参考的当前值。 | 
|  boolean |  isMarked() 返回标记的当前值。 | 
|  void |  set(V newReference, boolean newMark) 无条件地设置参考和标记的值。 | 
|  boolean |  weakCompareAndSet(V expectedReference, V newReference, boolean expectedMark, boolean newMark) 如果当前参考值为预期参考值的  | 
| Inherited methods | |
|---|---|
|  From class  java.lang.Object  | |
AtomicMarkableReference (V initialRef, 
                boolean initialMark) 
     用给定的初始值创建一个新的 AtomicMarkableReference 。
| Parameters | |
|---|---|
| initialRef | V: the initial reference | 
| initialMark | boolean: the initial mark | 
boolean attemptMark (V expectedReference, 
                boolean newMark) 
     如果当前参考值为预期参考值的== ,则以原子方式将标记值设置为给定更新值。 任何给定的此操作调用可能会失败(返回false ),但当当前值保持期望值并且没有其他线程也试图设置值时重复调用将最终成功。
| Parameters | |
|---|---|
| expectedReference | V: the expected value of the reference | 
| newMark | boolean: the new value for the mark | 
| Returns | |
|---|---|
| boolean | trueif successful | 
boolean compareAndSet (V expectedReference, 
                V newReference, 
                boolean expectedMark, 
                boolean newMark) 
     如果当前参考值为预期参考值的 == ,且当前标志值等于预期标志值,则将参考值和标志值同时设定为给定更新值。
| Parameters | |
|---|---|
| expectedReference | V: the expected value of the reference | 
| newReference | V: the new value for the reference | 
| expectedMark | boolean: the expected value of the mark | 
| newMark | boolean: the new value for the mark | 
| Returns | |
|---|---|
| boolean | trueif successful | 
V get (boolean[] markHolder)
返回参考和标记的当前值。 典型用法是boolean[1] holder; ref = v.get(holder); 。
| Parameters | |
|---|---|
| markHolder | boolean: an array of size of at least one. On return,markHolder[0]will hold the value of the mark. | 
| Returns | |
|---|---|
| V | the current value of the reference | 
V getReference ()
返回参考的当前值。
| Returns | |
|---|---|
| V | the current value of the reference | 
boolean isMarked ()
返回标记的当前值。
| Returns | |
|---|---|
| boolean | the current value of the mark | 
void set (V newReference, 
                boolean newMark) 
     无条件地设置参考和标记的值。
| Parameters | |
|---|---|
| newReference | V: the new value for the reference | 
| newMark | boolean: the new value for the mark | 
boolean weakCompareAndSet (V expectedReference, 
                V newReference, 
                boolean expectedMark, 
                boolean newMark) 
     如果当前参考值为预期参考值的 == ,并且当前标记等于预期标记,则以原子级方式将参考值和标记的值设置为给定更新值。
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 | 
| expectedMark | boolean: the expected value of the mark | 
| newMark | boolean: the new value for the mark | 
| Returns | |
|---|---|
| boolean | trueif successful |