T
- The type of the object holding the updatable fieldV
- The type of the fieldpublic abstract class UncheckedAtomicReferenceFieldUpdater<T,V> extends Object
class Node { private volatile Node left, right; private static final AtomicReferenceFieldUpdater<Node, Node> leftUpdater = AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "left"); private static AtomicReferenceFieldUpdater<Node, Node> rightUpdater = AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "right"); Node getLeft() { return left; } boolean compareAndSetLeft(Node expect, Node update) { return leftUpdater.compareAndSet(this, expect, update); } // ... and so on }
Note that the guarantees of the compareAndSet method in this class are weaker than in other atomic classes. Because this class cannot ensure that all uses of the field are appropriate for purposes of atomic access, it can guarantee atomicity and volatile semantics only with respect to other invocations of compareAndSet and set.
Constructor and Description |
---|
UncheckedAtomicReferenceFieldUpdater() |
Modifier and Type | Method and Description |
---|---|
static <U,W> AtomicReferenceFieldUpdater<U,W> |
newUpdater(Class<U> tclass,
Class<W> vclass,
String fieldName)
Creates an updater for objects with the given field.
|
public UncheckedAtomicReferenceFieldUpdater()
public static <U,W> AtomicReferenceFieldUpdater<U,W> newUpdater(Class<U> tclass, Class<W> vclass, String fieldName)
tclass
- the class of the objects holding the field.vclass
- the class of the fieldfieldName
- the name of the field to be updated.IllegalArgumentException
- if the field is not a volatile reference type.RuntimeException
- with a nested reflection-based exception if the class does
not hold field or is the wrong type.Copyright © GigaSpaces.