Liking cljdoc? Tell your friends :D

jdk.util.concurrent.atomic.AtomicReferenceFieldUpdater

A reflection-based utility that enables atomic updates to designated volatile reference fields of designated classes. This class is designed for use in atomic data structures in which several reference fields of the same node are independently subject to atomic updates. For example, a tree node might be declared as

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 only with respect to other invocations of compareAndSet and set on the same updater.

A reflection-based utility that enables atomic updates to
designated volatile reference fields of designated
classes.  This class is designed for use in atomic data structures
in which several reference fields of the same node are
independently subject to atomic updates. For example, a tree node
might be declared as



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 only with respect to other invocations of
compareAndSet and set on the same updater.
raw docstring

*new-updaterclj

(*new-updater tclass vclass field-name)

Creates and returns an updater for objects with the given field. The Class arguments are needed to check that reflective types and generic types match.

tclass - the class of the objects holding the field - java.lang.Class vclass - the class of the field - java.lang.Class field-name - the name of the field to be updated - java.lang.String

returns: the updater - <U,W> java.util.concurrent.atomic.AtomicReferenceFieldUpdater<U,W>

throws: java.lang.ClassCastException - if the field is of the wrong type

Creates and returns an updater for objects with the given field.
 The Class arguments are needed to check that reflective types and
 generic types match.

tclass - the class of the objects holding the field - `java.lang.Class`
vclass - the class of the field - `java.lang.Class`
field-name - the name of the field to be updated - `java.lang.String`

returns: the updater - `<U,W> java.util.concurrent.atomic.AtomicReferenceFieldUpdater<U,W>`

throws: java.lang.ClassCastException - if the field is of the wrong type
raw docstring

accumulate-and-getclj

(accumulate-and-get this obj x accumulator-function)

Atomically updates the field of the given object managed by this updater with the results of applying the given function to the current and given values, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.

obj - An object whose field to get and set - T x - the update value - V accumulator-function - a side-effect-free function of two arguments - java.util.function.BinaryOperator

returns: the updated value - V

Atomically updates the field of the given object managed by this
 updater with the results of applying the given function to the
 current and given values, returning the updated value. The
 function should be side-effect-free, since it may be re-applied
 when attempted updates fail due to contention among threads.  The
 function is applied with the current value as its first argument,
 and the given update as the second argument.

obj - An object whose field to get and set - `T`
x - the update value - `V`
accumulator-function - a side-effect-free function of two arguments - `java.util.function.BinaryOperator`

returns: the updated value - `V`
raw docstring

compare-and-setclj

(compare-and-set this obj expect update)

Atomically sets the field of the given object managed by this updater to the given updated value if the current value == the expected value. This method is guaranteed to be atomic with respect to other calls to compareAndSet and set, but not necessarily with respect to other changes in the field.

obj - An object whose field to conditionally set - T expect - the expected value - V update - the new value - V

returns: true if successful - boolean

Atomically sets the field of the given object managed by this updater
 to the given updated value if the current value == the
 expected value. This method is guaranteed to be atomic with respect to
 other calls to compareAndSet and set, but not
 necessarily with respect to other changes in the field.

obj - An object whose field to conditionally set - `T`
expect - the expected value - `V`
update - the new value - `V`

returns: true if successful - `boolean`
raw docstring

getclj

(get this obj)

Gets the current value held in the field of the given object managed by this updater.

obj - An object whose field to get - T

returns: the current value - V

Gets the current value held in the field of the given object managed
 by this updater.

obj - An object whose field to get - `T`

returns: the current value - `V`
raw docstring

get-and-accumulateclj

(get-and-accumulate this obj x accumulator-function)

Atomically updates the field of the given object managed by this updater with the results of applying the given function to the current and given values, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.

obj - An object whose field to get and set - T x - the update value - V accumulator-function - a side-effect-free function of two arguments - java.util.function.BinaryOperator

returns: the previous value - V

Atomically updates the field of the given object managed by this
 updater with the results of applying the given function to the
 current and given values, returning the previous value. The
 function should be side-effect-free, since it may be re-applied
 when attempted updates fail due to contention among threads.  The
 function is applied with the current value as its first argument,
 and the given update as the second argument.

obj - An object whose field to get and set - `T`
x - the update value - `V`
accumulator-function - a side-effect-free function of two arguments - `java.util.function.BinaryOperator`

returns: the previous value - `V`
raw docstring

get-and-setclj

(get-and-set this obj new-value)

Atomically sets the field of the given object managed by this updater to the given value and returns the old value.

obj - An object whose field to get and set - T new-value - the new value - V

returns: the previous value - V

Atomically sets the field of the given object managed by this updater
 to the given value and returns the old value.

obj - An object whose field to get and set - `T`
new-value - the new value - `V`

returns: the previous value - `V`
raw docstring

get-and-updateclj

(get-and-update this obj update-function)

Atomically updates the field of the given object managed by this updater with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

obj - An object whose field to get and set - T update-function - a side-effect-free function - java.util.function.UnaryOperator

returns: the previous value - V

Atomically updates the field of the given object managed by this updater
 with the results of applying the given function, returning the previous
 value. The function should be side-effect-free, since it may be
 re-applied when attempted updates fail due to contention among threads.

obj - An object whose field to get and set - `T`
update-function - a side-effect-free function - `java.util.function.UnaryOperator`

returns: the previous value - `V`
raw docstring

lazy-setclj

(lazy-set this obj new-value)

Eventually sets the field of the given object managed by this updater to the given updated value.

obj - An object whose field to set - T new-value - the new value - V

Eventually sets the field of the given object managed by this
 updater to the given updated value.

obj - An object whose field to set - `T`
new-value - the new value - `V`
raw docstring

setclj

(set this obj new-value)

Sets the field of the given object managed by this updater to the given updated value. This operation is guaranteed to act as a volatile store with respect to subsequent invocations of compareAndSet.

obj - An object whose field to set - T new-value - the new value - V

Sets the field of the given object managed by this updater to the
 given updated value. This operation is guaranteed to act as a volatile
 store with respect to subsequent invocations of compareAndSet.

obj - An object whose field to set - `T`
new-value - the new value - `V`
raw docstring

update-and-getclj

(update-and-get this obj update-function)

Atomically updates the field of the given object managed by this updater with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

obj - An object whose field to get and set - T update-function - a side-effect-free function - java.util.function.UnaryOperator

returns: the updated value - V

Atomically updates the field of the given object managed by this updater
 with the results of applying the given function, returning the updated
 value. The function should be side-effect-free, since it may be
 re-applied when attempted updates fail due to contention among threads.

obj - An object whose field to get and set - `T`
update-function - a side-effect-free function - `java.util.function.UnaryOperator`

returns: the updated value - `V`
raw docstring

weak-compare-and-setclj

(weak-compare-and-set this obj expect update)

Atomically sets the field of the given object managed by this updater to the given updated value if the current value == the expected value. This method is guaranteed to be atomic with respect to other calls to compareAndSet and set, but not necessarily with respect to other changes in the field.

May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet.

obj - An object whose field to conditionally set - T expect - the expected value - V update - the new value - V

returns: true if successful - boolean

Atomically sets the field of the given object managed by this updater
 to the given updated value if the current value == the
 expected value. This method is guaranteed to be atomic with respect to
 other calls to compareAndSet and set, but not
 necessarily with respect to other changes in the field.

 May fail
 spuriously and does not provide ordering guarantees, so is
 only rarely an appropriate alternative to compareAndSet.

obj - An object whose field to conditionally set - `T`
expect - the expected value - `V`
update - the new value - `V`

returns: true if successful - `boolean`
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close