AtomicLongArray
open class AtomicLongArray : Serializable
| kotlin.Any | |
| ↳ | java.util.concurrent.atomic.AtomicLongArray |
A long array in which elements may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables.
Summary
| Public constructors | |
|---|---|
|
Creates a new AtomicLongArray of the given length, with all elements initially zero. |
|
|
Creates a new AtomicLongArray with the same length as, and all elements copied from, the given array. |
|
| Public methods | |
|---|---|
| Long |
accumulateAndGet(i: Int, x: Long, accumulatorFunction: LongBinaryOperator!)Atomically updates the element at index |
| open Long |
Atomically adds the given value to the element at index |
| Boolean |
compareAndSet(i: Int, expect: Long, update: Long)Atomically sets the element at position |
| Long |
decrementAndGet(i: Int)Atomically decrements by one the element at index |
| Long |
Gets the current value at position |
| Long |
getAndAccumulate(i: Int, x: Long, accumulatorFunction: LongBinaryOperator!)Atomically updates the element at index |
| Long |
Atomically adds the given value to the element at index |
| Long |
getAndDecrement(i: Int)Atomically decrements by one the element at index |
| Long |
getAndIncrement(i: Int)Atomically increments by one the element at index |
| Long |
Atomically sets the element at position |
| Long |
getAndUpdate(i: Int, updateFunction: LongUnaryOperator!)Atomically updates the element at index |
| Long |
incrementAndGet(i: Int)Atomically increments by one the element at index |
| Unit |
Eventually sets the element at position |
| Int |
length()Returns the length of the array. |
| Unit |
Sets the element at position |
| open String |
toString()Returns the String representation of the current values of array. |
| Long |
updateAndGet(i: Int, updateFunction: LongUnaryOperator!)Atomically updates the element at index |
| Boolean |
weakCompareAndSet(i: Int, expect: Long, update: Long)Atomically sets the element at position |
Public constructors
<init>
AtomicLongArray(length: Int)
Creates a new AtomicLongArray of the given length, with all elements initially zero.
| Parameters | |
|---|---|
length |
Int: the length of the array |
<init>
AtomicLongArray(array: LongArray!)
Creates a new AtomicLongArray with the same length as, and all elements copied from, the given array.
| Parameters | |
|---|---|
array |
LongArray!: the array to copy elements from |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
if array is null |
Public methods
accumulateAndGet
fun accumulateAndGet(
i: Int,
x: Long,
accumulatorFunction: LongBinaryOperator!
): Long
Atomically updates 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 at index i as its first argument, and the given update as the second argument.
| Parameters | |
|---|---|
i |
Int: the index |
x |
Long: the update value |
accumulatorFunction |
LongBinaryOperator!: a side-effect-free function of two arguments |
| Return | |
|---|---|
Long |
the updated value |
addAndGet
open fun addAndGet(
i: Int,
delta: Long
): Long
Atomically adds the given value to the element at index i.
| Parameters | |
|---|---|
i |
Int: the index |
delta |
Long: the value to add |
| Return | |
|---|---|
Long |
the updated value |
compareAndSet
fun compareAndSet(
i: Int,
expect: Long,
update: Long
): Boolean
Atomically sets the element at position i to the given updated value if the current value == the expected value.
| Parameters | |
|---|---|
i |
Int: the index |
expect |
Long: the expected value |
update |
Long: 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): Long
Atomically decrements by one the element at index i.
| Parameters | |
|---|---|
i |
Int: the index |
| Return | |
|---|---|
Long |
the updated value |
get
fun get(i: Int): Long
Gets the current value at position i.
| Parameters | |
|---|---|
i |
Int: the index |
| Return | |
|---|---|
Long |
the current value |
getAndAccumulate
fun getAndAccumulate(
i: Int,
x: Long,
accumulatorFunction: LongBinaryOperator!
): Long
Atomically updates 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 at index i as its first argument, and the given update as the second argument.
| Parameters | |
|---|---|
i |
Int: the index |
x |
Long: the update value |
accumulatorFunction |
LongBinaryOperator!: a side-effect-free function of two arguments |
| Return | |
|---|---|
Long |
the previous value |
getAndAdd
fun getAndAdd(
i: Int,
delta: Long
): Long
Atomically adds the given value to the element at index i.
| Parameters | |
|---|---|
i |
Int: the index |
delta |
Long: the value to add |
| Return | |
|---|---|
Long |
the previous value |
getAndDecrement
fun getAndDecrement(i: Int): Long
Atomically decrements by one the element at index i.
| Parameters | |
|---|---|
i |
Int: the index |
| Return | |
|---|---|
Long |
the previous value |
getAndIncrement
fun getAndIncrement(i: Int): Long
Atomically increments by one the element at index i.
| Parameters | |
|---|---|
i |
Int: the index |
| Return | |
|---|---|
Long |
the previous value |
getAndSet
fun getAndSet(
i: Int,
newValue: Long
): Long
Atomically sets the element at position i to the given value and returns the old value.
| Parameters | |
|---|---|
i |
Int: the index |
newValue |
Long: the new value |
| Return | |
|---|---|
Long |
the previous value |
getAndUpdate
fun getAndUpdate(
i: Int,
updateFunction: LongUnaryOperator!
): Long
Atomically updates 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 |
LongUnaryOperator!: a side-effect-free function |
| Return | |
|---|---|
Long |
the previous value |
incrementAndGet
fun incrementAndGet(i: Int): Long
Atomically increments by one the element at index i.
| Parameters | |
|---|---|
i |
Int: the index |
| Return | |
|---|---|
Long |
the updated value |
lazySet
fun lazySet(
i: Int,
newValue: Long
): Unit
Eventually sets the element at position i to the given value.
| Parameters | |
|---|---|
i |
Int: the index |
newValue |
Long: 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: Long
): Unit
Sets the element at position i to the given value.
| Parameters | |
|---|---|
i |
Int: the index |
newValue |
Long: 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: LongUnaryOperator!
): Long
Atomically updates 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 |
LongUnaryOperator!: a side-effect-free function |
| Return | |
|---|---|
Long |
the updated value |
weakCompareAndSet
fun weakCompareAndSet(
i: Int,
expect: Long,
update: Long
): Boolean
Atomically sets the element at position i to the given updated value if the current value == the expected value.
May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet.
| Parameters | |
|---|---|
i |
Int: the index |
expect |
Long: the expected value |
update |
Long: the new value |
| Return | |
|---|---|
Boolean |
true if successful |