Added in API level 1

AtomicReferenceArray

open class AtomicReferenceArray<E : Any!> : Serializable
kotlin.Any
   ↳ java.util.concurrent.atomic.AtomicReferenceArray

An array of object references 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 AtomicReferenceArray of the given length, with all elements initially null.

Creates a new AtomicReferenceArray with the same length as, and all elements copied from, the given array.

Public methods
E
accumulateAndGet(i: Int, x: E, accumulatorFunction: BinaryOperator<E>!)

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.

Boolean
compareAndSet(i: Int, expect: E, update: E)

Atomically sets the element at position i to the given updated value if the current value == the expected value.

E
get(i: Int)

Gets the current value at position i.

E
getAndAccumulate(i: Int, x: E, accumulatorFunction: BinaryOperator<E>!)

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.

E
getAndSet(i: Int, newValue: E)

Atomically sets the element at position i to the given value and returns the old value.

E
getAndUpdate(i: Int, updateFunction: UnaryOperator<E>!)

Atomically updates the element at index i with the results of applying the given function, returning the previous value.

Unit
lazySet(i: Int, newValue: E)

Eventually sets the element at position i to the given value.

Int

Returns the length of the array.

Unit
set(i: Int, newValue: E)

Sets the element at position i to the given value.

open String

Returns the String representation of the current values of array.

E
updateAndGet(i: Int, updateFunction: UnaryOperator<E>!)

Atomically updates the element at index i with the results of applying the given function, returning the updated value.

Boolean
weakCompareAndSet(i: Int, expect: E, update: E)

Atomically sets the element at position i to the given updated value if the current value == the expected value.

Public constructors

AtomicReferenceArray

Added in API level 1
AtomicReferenceArray(length: Int)

Creates a new AtomicReferenceArray of the given length, with all elements initially null.

Parameters
length Int: the length of the array

AtomicReferenceArray

Added in API level 1
AtomicReferenceArray(array: Array<E>!)

Creates a new AtomicReferenceArray with the same length as, and all elements copied from, the given array.

Parameters
array Array<E>!: the array to copy elements from
Exceptions
java.lang.NullPointerException if array is null

Public methods

accumulateAndGet

Added in API level 24
fun accumulateAndGet(
    i: Int,
    x: E,
    accumulatorFunction: BinaryOperator<E>!
): E

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 E: the update value
accumulatorFunction BinaryOperator<E>!: a side-effect-free function of two arguments
Return
E the updated value

compareAndSet

Added in API level 1
fun compareAndSet(
    i: Int,
    expect: E,
    update: E
): 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 E: the expected value
update E: the new value
Return
Boolean true if successful. False return indicates that the actual value was not equal to the expected value.

get

Added in API level 1
fun get(i: Int): E

Gets the current value at position i.

Parameters
i Int: the index
Return
E the current value

getAndAccumulate

Added in API level 24
fun getAndAccumulate(
    i: Int,
    x: E,
    accumulatorFunction: BinaryOperator<E>!
): E

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 E: the update value
accumulatorFunction BinaryOperator<E>!: a side-effect-free function of two arguments
Return
E the previous value

getAndSet

Added in API level 1
fun getAndSet(
    i: Int,
    newValue: E
): E

Atomically sets the element at position i to the given value and returns the old value.

Parameters
i Int: the index
newValue E: the new value
Return
E the previous value

getAndUpdate

Added in API level 24
fun getAndUpdate(
    i: Int,
    updateFunction: UnaryOperator<E>!
): E

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 UnaryOperator<E>!: a side-effect-free function
Return
E the previous value

lazySet

Added in API level 9
fun lazySet(
    i: Int,
    newValue: E
): Unit

Eventually sets the element at position i to the given value.

Parameters
i Int: the index
newValue E: the new value

length

Added in API level 1
fun length(): Int

Returns the length of the array.

Return
Int the length of the array

set

Added in API level 1
fun set(
    i: Int,
    newValue: E
): Unit

Sets the element at position i to the given value.

Parameters
i Int: the index
newValue E: the new value

toString

Added in API level 1
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

Added in API level 24
fun updateAndGet(
    i: Int,
    updateFunction: UnaryOperator<E>!
): E

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 UnaryOperator<E>!: a side-effect-free function
Return
E the updated value

weakCompareAndSet

Added in API level 1
fun weakCompareAndSet(
    i: Int,
    expect: E,
    update: E
): 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 E: the expected value
update E: the new value
Return
Boolean true if successful