AtomicLongFieldUpdater
abstract class AtomicLongFieldUpdater<T : Any!>
kotlin.Any | |
↳ | java.util.concurrent.atomic.AtomicLongFieldUpdater |
A reflection-based utility that enables atomic updates to designated volatile long
fields of designated classes. This class is designed for use in atomic data structures in which several fields of the same node are independently subject to atomic updates.
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.
Object arguments for parameters of type T
that are not instances of the class passed to newUpdater
will result in a ClassCastException
being thrown.
Summary
Protected constructors | |
---|---|
Protected do-nothing constructor for use by subclasses. |
Public methods | |
---|---|
Long |
accumulateAndGet(obj: T, x: Long, accumulatorFunction: LongBinaryOperator!) Atomically updates (with memory effects as specified by |
open Long |
Atomically adds the given value to the current value of the field of the given object managed by this updater. |
abstract Boolean |
compareAndSet(obj: T, expect: Long, update: Long) Atomically sets the field of the given object managed by this updater to the given updated value if the current value |
open Long |
decrementAndGet(obj: T) Atomically decrements by one the current value of the field of the given object managed by this updater. |
abstract Long |
get(obj: T) Returns the current value held in the field of the given object managed by this updater. |
Long |
getAndAccumulate(obj: T, x: Long, accumulatorFunction: LongBinaryOperator!) Atomically updates (with memory effects as specified by |
open Long |
Atomically adds the given value to the current value of the field of the given object managed by this updater. |
open Long |
getAndDecrement(obj: T) Atomically decrements by one the current value of the field of the given object managed by this updater. |
open Long |
getAndIncrement(obj: T) Atomically increments by one the current value of the field of the given object managed by this updater. |
open Long |
Atomically sets the field of the given object managed by this updater to the given value and returns the old value. |
Long |
getAndUpdate(obj: T, updateFunction: LongUnaryOperator!) Atomically updates (with memory effects as specified by |
open Long |
incrementAndGet(obj: T) Atomically increments by one the current value of the field of the given object managed by this updater. |
abstract Unit |
Eventually sets the field of the given object managed by this updater to the given updated value. |
open static AtomicLongFieldUpdater<U>! |
newUpdater(tclass: Class<U>!, fieldName: String!) Creates and returns an updater for objects with the given field. |
abstract Unit |
Sets the field of the given object managed by this updater to the given updated value. |
Long |
updateAndGet(obj: T, updateFunction: LongUnaryOperator!) Atomically updates (with memory effects as specified by |
abstract Boolean |
weakCompareAndSet(obj: T, expect: Long, update: Long) Atomically sets the field of the given object managed by this updater to the given updated value if the current value |
Protected constructors
AtomicLongFieldUpdater
protected AtomicLongFieldUpdater()
Protected do-nothing constructor for use by subclasses.
Public methods
accumulateAndGet
fun accumulateAndGet(
obj: T,
x: Long,
accumulatorFunction: LongBinaryOperator!
): Long
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) 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.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
x |
Long: the update value |
accumulatorFunction |
LongBinaryOperator!: a side-effect-free function of two arguments |
Return | |
---|---|
Long |
the updated value |
addAndGet
open fun addAndGet(
obj: T,
delta: Long
): Long
Atomically adds the given value to the current value of the field of the given object managed by this updater.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
delta |
Long: the value to add |
Return | |
---|---|
Long |
the updated value |
compareAndSet
abstract fun compareAndSet(
obj: T,
expect: Long,
update: Long
): 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.
Parameters | |
---|---|
obj |
T: An object whose field to conditionally set |
expect |
Long: the expected value |
update |
Long: the new value |
Return | |
---|---|
Boolean |
true if successful |
decrementAndGet
open fun decrementAndGet(obj: T): Long
Atomically decrements by one the current value of the field of the given object managed by this updater.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
Return | |
---|---|
Long |
the updated value |
get
abstract fun get(obj: T): Long
Returns the current value held in the field of the given object managed by this updater.
Parameters | |
---|---|
obj |
T: An object whose field to get |
Return | |
---|---|
Long |
the current value |
getAndAccumulate
fun getAndAccumulate(
obj: T,
x: Long,
accumulatorFunction: LongBinaryOperator!
): Long
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) 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.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
x |
Long: the update value |
accumulatorFunction |
LongBinaryOperator!: a side-effect-free function of two arguments |
Return | |
---|---|
Long |
the previous value |
getAndAdd
open fun getAndAdd(
obj: T,
delta: Long
): Long
Atomically adds the given value to the current value of the field of the given object managed by this updater.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
delta |
Long: the value to add |
Return | |
---|---|
Long |
the previous value |
getAndDecrement
open fun getAndDecrement(obj: T): Long
Atomically decrements by one the current value of the field of the given object managed by this updater.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
Return | |
---|---|
Long |
the previous value |
getAndIncrement
open fun getAndIncrement(obj: T): Long
Atomically increments by one the current value of the field of the given object managed by this updater.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
Return | |
---|---|
Long |
the previous value |
getAndSet
open fun getAndSet(
obj: T,
newValue: Long
): Long
Atomically sets the field of the given object managed by this updater to the given value and returns the old value.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
newValue |
Long: the new value |
Return | |
---|---|
Long |
the previous value |
getAndUpdate
fun getAndUpdate(
obj: T,
updateFunction: LongUnaryOperator!
): Long
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) 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.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
updateFunction |
LongUnaryOperator!: a side-effect-free function |
Return | |
---|---|
Long |
the previous value |
incrementAndGet
open fun incrementAndGet(obj: T): Long
Atomically increments by one the current value of the field of the given object managed by this updater.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
Return | |
---|---|
Long |
the updated value |
lazySet
abstract fun lazySet(
obj: T,
newValue: Long
): Unit
Eventually sets the field of the given object managed by this updater to the given updated value.
Parameters | |
---|---|
obj |
T: An object whose field to set |
newValue |
Long: the new value |
newUpdater
open static fun <U : Any!> newUpdater(
tclass: Class<U>!,
fieldName: String!
): AtomicLongFieldUpdater<U>!
Creates and returns an updater for objects with the given field. The Class argument is needed to check that reflective types and generic types match.
Parameters | |
---|---|
tclass |
Class<U>!: the class of the objects holding the field |
fieldName |
String!: the name of the field to be updated |
<U> |
the type of instances of tclass |
Return | |
---|---|
AtomicLongFieldUpdater<U>! |
the updater |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the field is not a volatile long type |
java.lang.RuntimeException |
with a nested reflection-based exception if the class does not hold field or is the wrong type, or the field is inaccessible to the caller according to Java language access control |
set
abstract fun set(
obj: T,
newValue: Long
): Unit
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
.
Parameters | |
---|---|
obj |
T: An object whose field to set |
newValue |
Long: the new value |
updateAndGet
fun updateAndGet(
obj: T,
updateFunction: LongUnaryOperator!
): Long
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) 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.
Parameters | |
---|---|
obj |
T: An object whose field to get and set |
updateFunction |
LongUnaryOperator!: a side-effect-free function |
Return | |
---|---|
Long |
the updated value |
weakCompareAndSet
abstract fun weakCompareAndSet(
obj: T,
expect: Long,
update: Long
): 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.
This operation may fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet
.
Parameters | |
---|---|
obj |
T: An object whose field to conditionally set |
expect |
Long: the expected value |
update |
Long: the new value |
Return | |
---|---|
Boolean |
true if successful |