Added in API level 1

AtomicBoolean

open class AtomicBoolean : Serializable
kotlin.Any
   ↳ java.util.concurrent.atomic.AtomicBoolean

A boolean value that may be updated atomically. See the VarHandle specification for descriptions of the properties of atomic accesses. An AtomicBoolean is used in applications such as atomically updated flags, and cannot be used as a replacement for a java.lang.Boolean.

Summary

Public constructors

Creates a new AtomicBoolean with initial value false.

AtomicBoolean(initialValue: Boolean)

Creates a new AtomicBoolean with the given initial value.

Public methods
Boolean
compareAndExchange(expectedValue: Boolean, newValue: Boolean)

Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue, with memory effects as specified by VarHandle.compareAndExchange.

Boolean
compareAndExchangeAcquire(expectedValue: Boolean, newValue: Boolean)

Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue, with memory effects as specified by VarHandle.compareAndExchangeAcquire.

Boolean
compareAndExchangeRelease(expectedValue: Boolean, newValue: Boolean)

Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue, with memory effects as specified by VarHandle.compareAndExchangeRelease.

Boolean
compareAndSet(expectedValue: Boolean, newValue: Boolean)

Atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.compareAndSet.

Boolean
get()

Returns the current value, with memory effects as specified by VarHandle.getVolatile.

Boolean

Returns the current value, with memory effects as specified by VarHandle.getAcquire.

Boolean
getAndSet(newValue: Boolean)

Atomically sets the value to newValue and returns the old value, with memory effects as specified by VarHandle.getAndSet.

Boolean

Returns the current value, with memory effects as specified by VarHandle.getOpaque.

Boolean

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

Unit
lazySet(newValue: Boolean)

Sets the value to newValue, with memory effects as specified by VarHandle.setRelease.

Unit
set(newValue: Boolean)

Sets the value to newValue, with memory effects as specified by VarHandle.setVolatile.

Unit
setOpaque(newValue: Boolean)

Sets the value to newValue, with memory effects as specified by VarHandle.setOpaque.

Unit
setPlain(newValue: Boolean)

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

Unit
setRelease(newValue: Boolean)

Sets the value to newValue, with memory effects as specified by VarHandle.setRelease.

open String

Returns the String representation of the current value.

open Boolean
weakCompareAndSet(expectedValue: Boolean, newValue: Boolean)

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetPlain.

Boolean
weakCompareAndSetAcquire(expectedValue: Boolean, newValue: Boolean)

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetAcquire.

open Boolean
weakCompareAndSetPlain(expectedValue: Boolean, newValue: Boolean)

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetPlain.

Boolean
weakCompareAndSetRelease(expectedValue: Boolean, newValue: Boolean)

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetRelease.

Boolean
weakCompareAndSetVolatile(expectedValue: Boolean, newValue: Boolean)

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSet.

Public constructors

AtomicBoolean

Added in API level 1
AtomicBoolean()

Creates a new AtomicBoolean with initial value false.

AtomicBoolean

Added in API level 1
AtomicBoolean(initialValue: Boolean)

Creates a new AtomicBoolean with the given initial value.

Parameters
initialValue Boolean: the initial value

Public methods

compareAndExchange

Added in API level 33
fun compareAndExchange(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue, with memory effects as specified by VarHandle.compareAndExchange.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean the witness value, which will be the same as the expected value if successful

compareAndExchangeAcquire

Added in API level 33
fun compareAndExchangeAcquire(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue, with memory effects as specified by VarHandle.compareAndExchangeAcquire.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean the witness value, which will be the same as the expected value if successful

compareAndExchangeRelease

Added in API level 33
fun compareAndExchangeRelease(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue, with memory effects as specified by VarHandle.compareAndExchangeRelease.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean the witness value, which will be the same as the expected value if successful

compareAndSet

Added in API level 1
fun compareAndSet(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.compareAndSet.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: 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(): Boolean

Returns the current value, with memory effects as specified by VarHandle.getVolatile.

Return
Boolean the current value

getAcquire

Added in API level 33
fun getAcquire(): Boolean

Returns the current value, with memory effects as specified by VarHandle.getAcquire.

Return
Boolean the value

getAndSet

Added in API level 1
fun getAndSet(newValue: Boolean): Boolean

Atomically sets the value to newValue and returns the old value, with memory effects as specified by VarHandle.getAndSet.

Parameters
newValue Boolean: the new value
Return
Boolean the previous value

getOpaque

Added in API level 33
fun getOpaque(): Boolean

Returns the current value, with memory effects as specified by VarHandle.getOpaque.

Return
Boolean the value

getPlain

Added in API level 33
fun getPlain(): Boolean

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

Return
Boolean the value

lazySet

Added in API level 9
fun lazySet(newValue: Boolean): Unit

Sets the value to newValue, with memory effects as specified by VarHandle.setRelease.

Parameters
newValue Boolean: the new value

set

Added in API level 1
fun set(newValue: Boolean): Unit

Sets the value to newValue, with memory effects as specified by VarHandle.setVolatile.

Parameters
newValue Boolean: the new value

setOpaque

Added in API level 33
fun setOpaque(newValue: Boolean): Unit

Sets the value to newValue, with memory effects as specified by VarHandle.setOpaque.

Parameters
newValue Boolean: the new value

setPlain

Added in API level 33
fun setPlain(newValue: Boolean): Unit

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

Parameters
newValue Boolean: the new value

setRelease

Added in API level 33
fun setRelease(newValue: Boolean): Unit

Sets the value to newValue, with memory effects as specified by VarHandle.setRelease.

Parameters
newValue Boolean: the new value

toString

Added in API level 1
open fun toString(): String

Returns the String representation of the current value.

Return
String the String representation of the current value

weakCompareAndSet

Added in API level 1
Deprecated in API level 33
open fun weakCompareAndSet(
    expectedValue: Boolean,
    newValue: Boolean
): 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 value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetPlain.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean true if successful

weakCompareAndSetAcquire

Added in API level 33
fun weakCompareAndSetAcquire(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetAcquire.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean true if successful

weakCompareAndSetPlain

Added in API level 33
open fun weakCompareAndSetPlain(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetPlain.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean true if successful

weakCompareAndSetRelease

Added in API level 33
fun weakCompareAndSetRelease(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSetRelease.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean true if successful

weakCompareAndSetVolatile

Added in API level 33
fun weakCompareAndSetVolatile(
    expectedValue: Boolean,
    newValue: Boolean
): Boolean

Possibly atomically sets the value to newValue if the current value == expectedValue, with memory effects as specified by VarHandle.weakCompareAndSet.

Parameters
expectedValue Boolean: the expected value
newValue Boolean: the new value
Return
Boolean true if successful