AtomicLong
open class AtomicLong : Number, Serializable
| kotlin.Any | ||
| ↳ | kotlin.Number | |
| ↳ | java.util.concurrent.atomic.AtomicLong | |
A long value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables. An AtomicLong is used in applications such as atomically incremented sequence numbers, and cannot be used as a replacement for a java.lang.Long. However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes.
Summary
Public constructors |
|
|---|---|
|
Creates a new AtomicLong with the given initial value. |
|
<init>()Creates a new AtomicLong with initial value |
|
Public methods |
|
|---|---|
| Long |
accumulateAndGet(x: Long, accumulatorFunction: LongBinaryOperator!)Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value. |
| Long |
Atomically adds the given value to the current value. |
| Boolean |
compareAndSet(expect: Long, update: Long)Atomically sets the value to the given updated value if the current value |
| Long |
Atomically decrements by one the current value. |
| Long |
get()Gets the current value. |
| Long |
getAndAccumulate(x: Long, accumulatorFunction: LongBinaryOperator!)Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value. |
| Long |
Atomically adds the given value to the current value. |
| Long |
Atomically decrements by one the current value. |
| Long |
Atomically increments by one the current value. |
| Long |
Atomically sets to the given value and returns the old value. |
| Long |
getAndUpdate(updateFunction: LongUnaryOperator!)Atomically updates the current value with the results of applying the given function, returning the previous value. |
| Long |
Atomically increments by one the current value. |
| Unit |
Eventually sets to the given value. |
| Unit |
Sets to the given value. |
| open Double |
toDouble()Returns the value of this |
| open Float |
toFloat()Returns the value of this |
| open Int |
toInt()Returns the value of this |
| open Long |
toLong()Returns the value of this |
| open String |
toString()Returns the String representation of the current value. |
| Long |
updateAndGet(updateFunction: LongUnaryOperator!)Atomically updates the current value with the results of applying the given function, returning the updated value. |
| Boolean |
weakCompareAndSet(expect: Long, update: Long)Atomically sets the value to the given updated value if the current value |
Public constructors
<init>
AtomicLong(initialValue: Long)
Creates a new AtomicLong with the given initial value.
| Parameters | |
|---|---|
initialValue |
Long: the initial value |
Public methods
accumulateAndGet
fun accumulateAndGet(
x: Long,
accumulatorFunction: LongBinaryOperator!
): Long
Atomically updates the current value 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 as its first argument, and the given update as the second argument.
| Parameters | |
|---|---|
x |
Long: the update value |
accumulatorFunction |
LongBinaryOperator!: a side-effect-free function of two arguments |
| Return | |
|---|---|
Long |
the updated value |
addAndGet
fun addAndGet(delta: Long): Long
Atomically adds the given value to the current value.
| Parameters | |
|---|---|
delta |
Long: the value to add |
| Return | |
|---|---|
Long |
the updated value |
compareAndSet
fun compareAndSet(
expect: Long,
update: Long
): Boolean
Atomically sets the value to the given updated value if the current value == the expected value.
| Parameters | |
|---|---|
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(): Long
Atomically decrements by one the current value.
| Return | |
|---|---|
Long |
the updated value |
getAndAccumulate
fun getAndAccumulate(
x: Long,
accumulatorFunction: LongBinaryOperator!
): Long
Atomically updates the current value 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 as its first argument, and the given update as the second argument.
| Parameters | |
|---|---|
x |
Long: the update value |
accumulatorFunction |
LongBinaryOperator!: a side-effect-free function of two arguments |
| Return | |
|---|---|
Long |
the previous value |
getAndAdd
fun getAndAdd(delta: Long): Long
Atomically adds the given value to the current value.
| Parameters | |
|---|---|
delta |
Long: the value to add |
| Return | |
|---|---|
Long |
the previous value |
getAndDecrement
fun getAndDecrement(): Long
Atomically decrements by one the current value.
| Return | |
|---|---|
Long |
the previous value |
getAndIncrement
fun getAndIncrement(): Long
Atomically increments by one the current value.
| Return | |
|---|---|
Long |
the previous value |
getAndSet
fun getAndSet(newValue: Long): Long
Atomically sets to the given value and returns the old value.
| Parameters | |
|---|---|
newValue |
Long: the new value |
| Return | |
|---|---|
Long |
the previous value |
getAndUpdate
fun getAndUpdate(updateFunction: LongUnaryOperator!): Long
Atomically updates the current value 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 | |
|---|---|
updateFunction |
LongUnaryOperator!: a side-effect-free function |
| Return | |
|---|---|
Long |
the previous value |
incrementAndGet
fun incrementAndGet(): Long
Atomically increments by one the current value.
| Return | |
|---|---|
Long |
the updated value |
lazySet
fun lazySet(newValue: Long): Unit
Eventually sets to the given value.
| Parameters | |
|---|---|
newValue |
Long: the new value |
set
fun set(newValue: Long): Unit
Sets to the given value.
| Parameters | |
|---|---|
newValue |
Long: the new value |
toDouble
open fun toDouble(): Double
Returns the value of this AtomicLong as a double after a widening primitive conversion.
| Return | |
|---|---|
Double |
the numeric value represented by this object after conversion to type double. |
toFloat
open fun toFloat(): Float
Returns the value of this AtomicLong as a float after a widening primitive conversion.
| Return | |
|---|---|
Float |
the numeric value represented by this object after conversion to type float. |
toInt
open fun toInt(): Int
Returns the value of this AtomicLong as an int after a narrowing primitive conversion.
| Return | |
|---|---|
Int |
the numeric value represented by this object after conversion to type int. |
toLong
open fun toLong(): Long
Returns the value of this AtomicLong as a long. Equivalent to get().
| Return | |
|---|---|
Long |
the numeric value represented by this object after conversion to type long. |
toString
open fun toString(): String
Returns the String representation of the current value.
| Return | |
|---|---|
String |
the String representation of the current value |
updateAndGet
fun updateAndGet(updateFunction: LongUnaryOperator!): Long
Atomically updates the current value 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 | |
|---|---|
updateFunction |
LongUnaryOperator!: a side-effect-free function |
| Return | |
|---|---|
Long |
the updated value |
weakCompareAndSet
fun weakCompareAndSet(
expect: Long,
update: Long
): Boolean
Atomically sets the value 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 | |
|---|---|
expect |
Long: the expected value |
update |
Long: the new value |
| Return | |
|---|---|
Boolean |
true if successful |