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 VarHandle specification for descriptions of the properties of atomic accesses.

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 (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.

E
compareAndExchange(i: Int, expectedValue: E, newValue: E)

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.

E
compareAndExchangeAcquire(i: Int, expectedValue: E, newValue: E)

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.

E
compareAndExchangeRelease(i: Int, expectedValue: E, newValue: E)

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.

Boolean
compareAndSet(i: Int, expectedValue: E, newValue: E)

Atomically sets the element at index i to newValue if the element's current value == expectedValue, with memory effects as specified by VarHandle#compareAndSet.

E
get(i: Int)

Returns the current value of the element at index i, with memory effects as specified by VarHandle#getVolatile.

E

Returns the current value of the element at index i, with memory effects as specified by VarHandle#getAcquire.

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

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.

E
getAndSet(i: Int, newValue: E)

Atomically sets the element at index i to newValue and returns the old value, with memory effects as specified by VarHandle#getAndSet.

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

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.

E

Returns the current value of the element at index i, with memory effects as specified by VarHandle#getOpaque.

E

Returns the current value of the element at index i, with memory semantics of reading as if the variable was declared non-volatile.

Unit
lazySet(i: Int, newValue: E)

Sets the element at index i to newValue, with memory effects as specified by VarHandle#setRelease.

Int

Returns the length of the array.

Unit
set(i: Int, newValue: E)

Sets the element at index i to newValue, with memory effects as specified by VarHandle#setVolatile.

Unit
setOpaque(i: Int, newValue: E)

Sets the element at index i to newValue, with memory effects as specified by VarHandle#setOpaque.

Unit
setPlain(i: Int, newValue: E)

Sets the element at index i to newValue, with memory semantics of setting as if the variable was declared non-volatile and non-final.

Unit
setRelease(i: Int, newValue: E)

Sets the element at index i to newValue, with memory effects as specified by VarHandle#setRelease.

open String

Returns the String representation of the current values of array.

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

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.

Boolean
weakCompareAndSet(i: Int, expectedValue: E, newValue: E)

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.

Boolean
weakCompareAndSetAcquire(i: Int, expectedValue: E, newValue: E)

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.

Boolean
weakCompareAndSetPlain(i: Int, expectedValue: E, newValue: E)

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.

Boolean
weakCompareAndSetRelease(i: Int, expectedValue: E, newValue: E)

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.

Boolean
weakCompareAndSetVolatile(i: Int, expectedValue: E, newValue: E)

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.

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

compareAndExchange

Added in API level 33
fun compareAndExchange(
    i: Int,
    expectedValue: E,
    newValue: E
): E

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 E: the expected value
newValue E: the new value
Return
E the witness value, which will be the same as the expected value if successful

compareAndExchangeAcquire

Added in API level 33
fun compareAndExchangeAcquire(
    i: Int,
    expectedValue: E,
    newValue: E
): E

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 E: the expected value
newValue E: the new value
Return
E the witness value, which will be the same as the expected value if successful

compareAndExchangeRelease

Added in API level 33
fun compareAndExchangeRelease(
    i: Int,
    expectedValue: E,
    newValue: E
): E

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 E: the expected value
newValue E: the new value
Return
E the witness value, which will be the same as the expected value if successful

compareAndSet

Added in API level 1
fun compareAndSet(
    i: Int,
    expectedValue: E,
    newValue: E
): 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 E: the expected value
newValue 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

Returns the current value of the element at index i, with memory effects as specified by VarHandle#getVolatile.

Parameters
i Int: the index
Return
E the current value

getAcquire

Added in API level 33
fun getAcquire(i: Int): E

Returns the current value of the element at index i, with memory effects as specified by VarHandle#getAcquire.

Parameters
i Int: the index
Return
E the value

getAndAccumulate

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

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 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 index i to newValue and returns the old value, with memory effects as specified by VarHandle#getAndSet.

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

getOpaque

Added in API level 33
fun getOpaque(i: Int): E

Returns the current value of the element at index i, with memory effects as specified by VarHandle#getOpaque.

Parameters
i Int: the index
Return
E the value

getPlain

Added in API level 33
fun getPlain(i: Int): E

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
E the value

lazySet

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

Sets the element at index i to newValue, with memory effects as specified by VarHandle#setRelease.

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 index i to newValue, with memory effects as specified by VarHandle#setVolatile.

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

setOpaque

Added in API level 33
fun setOpaque(
    i: Int,
    newValue: E
): Unit

Sets the element at index i to newValue, with memory effects as specified by VarHandle#setOpaque.

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

setPlain

Added in API level 33
fun setPlain(
    i: Int,
    newValue: E
): 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 E: the new value

setRelease

Added in API level 33
fun setRelease(
    i: Int,
    newValue: E
): Unit

Sets the element at index i to newValue, with memory effects as specified by VarHandle#setRelease.

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

weakCompareAndSet

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

weakCompareAndSetAcquire

Added in API level 33
fun weakCompareAndSetAcquire(
    i: Int,
    expectedValue: E,
    newValue: E
): 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 E: the expected value
newValue E: the new value
Return
Boolean true if successful

weakCompareAndSetPlain

Added in API level 33
fun weakCompareAndSetPlain(
    i: Int,
    expectedValue: E,
    newValue: E
): 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 E: the expected value
newValue E: the new value
Return
Boolean true if successful

weakCompareAndSetRelease

Added in API level 33
fun weakCompareAndSetRelease(
    i: Int,
    expectedValue: E,
    newValue: E
): 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 E: the expected value
newValue E: the new value
Return
Boolean true if successful

weakCompareAndSetVolatile

Added in API level 33
fun weakCompareAndSetVolatile(
    i: Int,
    expectedValue: E,
    newValue: E
): 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 E: the expected value
newValue E: the new value
Return
Boolean true if successful