Added in API level 1

AtomicLong

public class AtomicLong
extends Number implements Serializable

java.lang.Object
   ↳ java.lang.Number
     ↳ java.util.concurrent.atomic.AtomicLong


A long value that may be updated atomically. See the VarHandle specification for descriptions of the properties of atomic accesses. An AtomicLong is used in applications such as atomically incremented sequence numbers, and cannot be used as a replacement for a Long. However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes.

Summary

Public constructors

AtomicLong()

Creates a new AtomicLong with initial value 0.

AtomicLong(long initialValue)

Creates a new AtomicLong with the given initial value.

Public methods

final long accumulateAndGet(long x, LongBinaryOperator accumulatorFunction)

Atomically updates (with memory effects as specified by VarHandle.compareAndSet) the current value with the results of applying the given function to the current and given values, returning the updated value.

final long addAndGet(long delta)

Atomically adds the given value to the current value, with memory effects as specified by VarHandle.getAndAdd.

final long compareAndExchange(long expectedValue, long newValue)

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.

final long compareAndExchangeAcquire(long expectedValue, long newValue)

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.

final long compareAndExchangeRelease(long expectedValue, long newValue)

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.

final boolean compareAndSet(long expectedValue, long newValue)

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

final long decrementAndGet()

Atomically decrements the current value, with memory effects as specified by VarHandle.getAndAdd.

double doubleValue()

Returns the current value of this AtomicLong as a double after a widening primitive conversion, with memory effects as specified by VarHandle.getVolatile.

float