1 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater* *AtomicReferenceFieldUpdater*
3 public abstract class AtomicReferenceFieldUpdater<T,V>
4 extends |java.lang.Object|
6 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater_Description|
7 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater_Fields|
8 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater_Constructors|
9 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater_Methods|
11 ================================================================================
13 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater_Constructors*
14 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater()|Protected do-nothing
16 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater_Methods*
17 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater.compareAndSet(T,V,V)|A
18 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater.get(T)|Gets the curren
19 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater.getAndSet(T,V)|Atomica
20 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater.lazySet(T,V)|Eventuall
21 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(Class<U>,Class<W>,String)|
22 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater.set(T,V)|Sets the fiel
23 |java.util.concurrent.atomic.AtomicReferenceFieldUpdater.weakCompareAndSet(T,V,V)|
25 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater_Description*
27 A reflection-based utility that enables atomic updates to
28 designatedvolatilereference fields of designated classes. This class is
29 designed for use in atomic data structures in which several reference fields of
30 the same node are independently subject to atomic updates. For example, a tree
31 node might be declared as
35 class Node { private volatile Node left, right;
37 private static final AtomicReferenceFieldUpdater<Node, Node> leftUpdater =
38 AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "left"); private
39 static AtomicReferenceFieldUpdater<Node, Node> rightUpdater =
40 AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "right");
42 Node getLeft() { return left; } boolean compareAndSetLeft(Node expect, Node
43 update) { return leftUpdater.compareAndSet(this, expect, update); } // ... and
46 Note that the guarantees of thecompareAndSetmethod in this class are weaker
47 than in other atomic classes. Because this class cannot ensure that all uses of
48 the field are appropriate for purposes of atomic access, it can guarantee
49 atomicity only with respect to other invocations ofcompareAndSetandseton the
54 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater()*
56 protected AtomicReferenceFieldUpdater()
58 Protected do-nothing constructor for use by subclasses.
61 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater.compareAndSet(T,V,V)*
63 public abstract boolean compareAndSet(
68 Atomically sets the field of the given object managed by this updater to the
69 given updated value if the current value==the expected value. This method is
70 guaranteed to be atomic with respect to other calls tocompareAndSetandset, but
71 not necessarily with respect to other changes in the field.
74 obj - An object whose field to conditionally set
75 expect - the expected value
76 update - the new value
78 Returns: true if successful.
80 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater.get(T)*
82 public abstract |V| get(T obj)
84 Gets the current value held in the field of the given object managed by this
88 obj - An object whose field to get
90 Returns: the current value
92 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater.getAndSet(T,V)*
98 Atomically sets the field of the given object managed by this updater to the
99 given value and returns the old value.
102 obj - An object whose field to get and set
103 newValue - the new value
105 Returns: the previous value
107 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater.lazySet(T,V)*
109 public abstract void lazySet(
113 Eventually sets the field of the given object managed by this updater to the
117 obj - An object whose field to set
118 newValue - the new value
120 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(Class<U>,Class<W>,String)*
122 public static |java.util.concurrent.atomic.AtomicReferenceFieldUpdater|<U,W> newUpdater(
123 java.lang.Class<U> tclass,
124 java.lang.Class<W> vclass,
125 java.lang.String fieldName)
127 Creates and returns an updater for objects with the given field. The Class
128 arguments are needed to check that reflective types and generic types match.
131 tclass - the class of the objects holding the field.
132 vclass - the class of the field
133 fieldName - the name of the field to be updated.
137 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater.set(T,V)*
139 public abstract void set(
143 Sets the field of the given object managed by this updater to the given updated
144 value. This operation is guaranteed to act as a volatile store with respect to
145 subsequent invocations ofcompareAndSet.
148 obj - An object whose field to set
149 newValue - the new value
151 *java.util.concurrent.atomic.AtomicReferenceFieldUpdater.weakCompareAndSet(T,V,V)*
153 public abstract boolean weakCompareAndSet(
158 Atomically sets the field of the given object managed by this updater to the
159 given updated value if the current value==the expected value. This method is
160 guaranteed to be atomic with respect to other calls tocompareAndSetandset, but
161 not necessarily with respect to other changes in the field.
163 May fail spuriously and does not provide ordering guarantees, so is only rarely
164 an appropriate alternative tocompareAndSet.
167 obj - An object whose field to conditionally set
168 expect - the expected value
169 update - the new value
171 Returns: true if successful.