AtomicIntegerArray
open class AtomicIntegerArray : Serializable
kotlin.Any | |
↳ | java.util.concurrent.atomic.AtomicIntegerArray |
An int
array in which elements may be updated atomically. See the VarHandle
specification for descriptions of the properties of atomic accesses.
Summary
Public constructors | |
---|---|
AtomicIntegerArray(length: Int) Creates a new AtomicIntegerArray of the given length, with all elements initially zero. |
|
AtomicIntegerArray(array: IntArray!) Creates a new AtomicIntegerArray with the same length as, and all elements copied from, the given array. |
Public methods | |
---|---|
Int |
accumulateAndGet(i: Int, x: Int, accumulatorFunction: IntBinaryOperator!) Atomically updates (with memory effects as specified by |
Int |
Atomically adds the given value to the element at index |
Int |
compareAndExchange(i: Int, expectedValue: Int, newValue: Int) Atomically sets the element at index |
Int |
compareAndExchangeAcquire(i: Int, expectedValue: Int, newValue: Int) Atomically sets the element at index |
Int |
compareAndExchangeRelease(i: Int, expectedValue: Int, newValue: Int) Atomically sets the element at index |
Boolean |
compareAndSet(i: Int, expectedValue: Int, newValue: Int) Atomically sets the element at index |
Int |
decrementAndGet(i: Int) Atomically decrements the value of the element at index |
Int |
Returns the current value of the element at index |
Int |
getAcquire(i: Int) Returns the current value of the element at index |
Int |
getAndAccumulate(i: Int, x: Int, accumulatorFunction: IntBinaryOperator!) Atomically updates (with memory effects as specified by |
Int |
Atomically adds the given value to the element at index |
Int |
getAndDecrement(i: Int) Atomically decrements the value of the element at index |
Int |
getAndIncrement(i: Int) Atomically increments the value of the element at index |
Int |
Atomically sets the element at index |
Int |
getAndUpdate(i: Int, updateFunction: IntUnaryOperator!) Atomically updates (with memory effects as specified by |
Int |
Returns the current value of the element at index |
Int |
Returns the current value of the element at index |
Int |
incrementAndGet(i: Int) Atomically increments the value of the element at index |
Unit |
Sets the element at index |
Int |
length() Returns the length of the array. |
Unit |
Sets the element at index |
Unit |
Sets the element at index |
Unit |
Sets the element at index |
Unit |
setRelease(i: Int, newValue: Int) Sets the element at index |
open String |
toString() Returns the String representation of the current values of array. |
Int |
updateAndGet(i: Int, updateFunction: IntUnaryOperator!) Atomically updates (with memory effects as specified by |
Boolean |
weakCompareAndSet(i: Int, expectedValue: Int, newValue: Int) Possibly atomically sets the element at index |
Boolean |
weakCompareAndSetAcquire(i: Int, expectedValue: Int, newValue: Int) Possibly atomically sets the element at index |
Boolean |
weakCompareAndSetPlain(i: Int, expectedValue: Int, newValue: Int) Possibly atomically sets the element at index |
Boolean |
weakCompareAndSetRelease(i: Int, expectedValue: Int, newValue: Int) Possibly atomically sets the element at index |
Boolean |
weakCompareAndSetVolatile(i: Int, expectedValue: Int, newValue: Int) Possibly atomically sets the element at index |
Public constructors
AtomicIntegerArray
AtomicIntegerArray(length: Int)
Creates a new AtomicIntegerArray of the given length, with all elements initially zero.
Parameters | |
---|---|
length |
Int: the length of the array |
AtomicIntegerArray
AtomicIntegerArray(array: IntArray!)
Creates a new AtomicIntegerArray with the same length as, and all elements copied from, the given array.
Parameters | |
---|---|
array |
IntArray!: the array to copy elements from |
Exceptions | |
---|---|
java.lang.NullPointerException |
if array is null |
Public methods
accumulateAndGet
fun accumulateAndGet(
i: Int,
x: Int,
accumulatorFunction: IntBinaryOperator!
): Int
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) the element at index i
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 of the element at index i
as its first argument, and the given update as the second argument.
Parameters | |
---|---|
i |
Int: the index |
x |
Int: the update value |
accumulatorFunction |
IntBinaryOperator!: a side-effect-free function of two arguments |
Return | |
---|---|
Int |
the updated value |
addAndGet
fun addAndGet(
i: Int,
delta: Int
): Int
Atomically adds the given value to the element at index i
, with memory effects as specified by VarHandle.getAndAdd
.
Parameters | |
---|---|
i |
Int: the index |
delta |
Int: the value to add |
Return | |
---|---|
Int |
the updated value |
compareAndExchange
fun compareAndExchange(
i: Int,
expectedValue: Int,
newValue: Int
): Int
Atomically sets the element at index i
to newValue
if the element's current value, referred to as the witness value, == expectedValue
, with memory effects as specified by VarHandle.compareAndExchange
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Int |
the witness value, which will be the same as the expected value if successful |
compareAndExchangeAcquire
fun compareAndExchangeAcquire(
i: Int,
expectedValue: Int,
newValue: Int
): Int
Atomically sets the element at index i
to newValue
if the element's current value, referred to as the witness value, == expectedValue
, with memory effects as specified by VarHandle.compareAndExchangeAcquire
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Int |
the witness value, which will be the same as the expected value if successful |
compareAndExchangeRelease
fun compareAndExchangeRelease(
i: Int,
expectedValue: Int,
newValue: Int
): Int
Atomically sets the element at index i
to newValue
if the element's current value, referred to as the witness value, == expectedValue
, with memory effects as specified by VarHandle.compareAndExchangeRelease
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Int |
the witness value, which will be the same as the expected value if successful |
compareAndSet
fun compareAndSet(
i: Int,
expectedValue: Int,
newValue: Int
): Boolean
Atomically sets the element at index i
to newValue
if the element's current value == expectedValue
, with memory effects as specified by VarHandle.compareAndSet
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Boolean |
true if successful. False return indicates that the actual value was not equal to the expected value. |
decrementAndGet
fun decrementAndGet(i: Int): Int
Atomically decrements the value of the element at index i
, with memory effects as specified by VarHandle.getAndAdd
.
Equivalent to addAndGet(i, -1)
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the updated value |
get
fun get(i: Int): Int
Returns the current value of the element at index i
, with memory effects as specified by VarHandle.getVolatile
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the current value |
getAcquire
fun getAcquire(i: Int): Int
Returns the current value of the element at index i
, with memory effects as specified by VarHandle.getAcquire
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the value |
getAndAccumulate
fun getAndAccumulate(
i: Int,
x: Int,
accumulatorFunction: IntBinaryOperator!
): Int
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) the element at index i
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 of the element at index i
as its first argument, and the given update as the second argument.
Parameters | |
---|---|
i |
Int: the index |
x |
Int: the update value |
accumulatorFunction |
IntBinaryOperator!: a side-effect-free function of two arguments |
Return | |
---|---|
Int |
the previous value |
getAndAdd
fun getAndAdd(
i: Int,
delta: Int
): Int
Atomically adds the given value to the element at index i
, with memory effects as specified by VarHandle.getAndAdd
.
Parameters | |
---|---|
i |
Int: the index |
delta |
Int: the value to add |
Return | |
---|---|
Int |
the previous value |
getAndDecrement
fun getAndDecrement(i: Int): Int
Atomically decrements the value of the element at index i
, with memory effects as specified by VarHandle.getAndAdd
.
Equivalent to getAndAdd(i, -1)
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the previous value |
getAndIncrement
fun getAndIncrement(i: Int): Int
Atomically increments the value of the element at index i
, with memory effects as specified by VarHandle.getAndAdd
.
Equivalent to getAndAdd(i, 1)
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the previous value |
getAndSet
fun getAndSet(
i: Int,
newValue: Int
): Int
Atomically sets the element at index i
to newValue
and returns the old value, with memory effects as specified by VarHandle.getAndSet
.
Parameters | |
---|---|
i |
Int: the index |
newValue |
Int: the new value |
Return | |
---|---|
Int |
the previous value |
getAndUpdate
fun getAndUpdate(
i: Int,
updateFunction: IntUnaryOperator!
): Int
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) the element at index i
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 | |
---|---|
i |
Int: the index |
updateFunction |
IntUnaryOperator!: a side-effect-free function |
Return | |
---|---|
Int |
the previous value |
getOpaque
fun getOpaque(i: Int): Int
Returns the current value of the element at index i
, with memory effects as specified by VarHandle.getOpaque
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the value |
getPlain
fun getPlain(i: Int): Int
Returns the current value of the element at index i
, with memory semantics of reading as if the variable was declared non-volatile
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the value |
incrementAndGet
fun incrementAndGet(i: Int): Int
Atomically increments the value of the element at index i
, with memory effects as specified by VarHandle.getAndAdd
.
Equivalent to addAndGet(i, 1)
.
Parameters | |
---|---|
i |
Int: the index |
Return | |
---|---|
Int |
the updated value |
lazySet
fun lazySet(
i: Int,
newValue: Int
): Unit
Sets the element at index i
to newValue
, with memory effects as specified by VarHandle.setRelease
.
Parameters | |
---|---|
i |
Int: the index |
newValue |
Int: the new value |
length
fun length(): Int
Returns the length of the array.
Return | |
---|---|
Int |
the length of the array |
set
fun set(
i: Int,
newValue: Int
): Unit
Sets the element at index i
to newValue
, with memory effects as specified by VarHandle.setVolatile
.
Parameters | |
---|---|
i |
Int: the index |
newValue |
Int: the new value |
setOpaque
fun setOpaque(
i: Int,
newValue: Int
): Unit
Sets the element at index i
to newValue
, with memory effects as specified by VarHandle.setOpaque
.
Parameters | |
---|---|
i |
Int: the index |
newValue |
Int: the new value |
setPlain
fun setPlain(
i: Int,
newValue: Int
): Unit
Sets the element at index i
to newValue
, with memory semantics of setting as if the variable was declared non-volatile
and non-final
.
Parameters | |
---|---|
i |
Int: the index |
newValue |
Int: the new value |
setRelease
fun setRelease(
i: Int,
newValue: Int
): Unit
Sets the element at index i
to newValue
, with memory effects as specified by VarHandle.setRelease
.
Parameters | |
---|---|
i |
Int: the index |
newValue |
Int: the new value |
toString
open fun toString(): String
Returns the String representation of the current values of array.
Return | |
---|---|
String |
the String representation of the current values of array |
updateAndGet
fun updateAndGet(
i: Int,
updateFunction: IntUnaryOperator!
): Int
Atomically updates (with memory effects as specified by java.lang.invoke.VarHandle#compareAndSet
) the element at index i
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 | |
---|---|
i |
Int: the index |
updateFunction |
IntUnaryOperator!: a side-effect-free function |
Return | |
---|---|
Int |
the updated value |
weakCompareAndSet
funweakCompareAndSet(
i: Int,
expectedValue: Int,
newValue: Int
): Boolean
Deprecated: This method has plain memory effects but the method name implies volatile memory effects (see methods such as compareAndExchange
and compareAndSet
). To avoid confusion over plain or volatile memory effects it is recommended that the method weakCompareAndSetPlain
be used instead.
Possibly atomically sets the element at index i
to newValue
if the element's current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetPlain
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Boolean |
true if successful |
See Also
weakCompareAndSetAcquire
fun weakCompareAndSetAcquire(
i: Int,
expectedValue: Int,
newValue: Int
): Boolean
Possibly atomically sets the element at index i
to newValue
if the element's current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetAcquire
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Boolean |
true if successful |
weakCompareAndSetPlain
fun weakCompareAndSetPlain(
i: Int,
expectedValue: Int,
newValue: Int
): Boolean
Possibly atomically sets the element at index i
to newValue
if the element's current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetPlain
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Boolean |
true if successful |
weakCompareAndSetRelease
fun weakCompareAndSetRelease(
i: Int,
expectedValue: Int,
newValue: Int
): Boolean
Possibly atomically sets the element at index i
to newValue
if the element's current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSetRelease
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Boolean |
true if successful |
weakCompareAndSetVolatile
fun weakCompareAndSetVolatile(
i: Int,
expectedValue: Int,
newValue: Int
): Boolean
Possibly atomically sets the element at index i
to newValue
if the element's current value == expectedValue
, with memory effects as specified by VarHandle.weakCompareAndSet
.
Parameters | |
---|---|
i |
Int: the index |
expectedValue |
Int: the expected value |
newValue |
Int: the new value |
Return | |
---|---|
Boolean |
true if successful |