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 java.lang.Long . However, this class
does extend Number to allow uniform access by tools and
utilities that deal with numerically-based classes.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | |
| private static final Unsafe | |
| private static final long | |
| private volatile long |
| Access | Constructor and Description |
|---|---|
| public | AtomicLong(long
the initial value initialValue)Creates a new AtomicLong with the given initial value. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final long | Returns: the updated valuethe update value x, LongBinaryOperator a side-effect-free function of two arguments accumulatorFunction)Atomically updates (with memory effects as specified by |
| public final long | Returns: the updated valuethe value to add delta)Atomically adds the given value to the current value,
with memory effects as specified by |
| public final long | Returns: the witness value, which will be the same as the expected value if successfulthe expected value expectedValue, long the new value newValue)Atomically sets the value to |
| public final long | Returns: the witness value, which will be the same as the expected value if successfulthe expected value expectedValue, long the new value newValue)Atomically sets the value to |
| public final long | Returns: the witness value, which will be the same as the expected value if successfulthe expected value expectedValue, long the new value newValue)Atomically sets the value to |
| public final boolean | Returns: true if successful. False return indicates that
the actual value was not equal to the expected value.the expected value expectedValue, long the new value newValue)Atomically sets the value to |
| public final long | Returns: the updated valueAtomically decrements the current value,
with memory effects as specified by |
| public double | doubleValue()
Implements abstract java. Returns the current value of this |
| public float | floatValue()
Implements abstract java. Returns the current value of this |
| public final long | Returns: the current valueReturns the current value,
with memory effects as specified by |
| public final long | Returns: the valueReturns the current value,
with memory effects as specified by |
| public final long | Returns: the previous valuethe update value x, LongBinaryOperator a side-effect-free function of two arguments accumulatorFunction)Atomically updates (with memory effects as specified by |
| public final long | Returns: the previous valuethe value to add delta)Atomically adds the given value to the current value,
with memory effects as specified by |
| public final long | Returns: the previous valueAtomically decrements the current value,
with memory effects as specified by |
| public final long | Returns: the previous valueAtomically increments the current value,
with memory effects as specified by |
| public final long | Returns: the previous valuethe new value newValue)Atomically sets the value to |
| public final long | Returns: the previous valuea side-effect-free function updateFunction)Atomically updates (with memory effects as specified by |
| public final long | Returns: the valueReturns the current value,
with memory effects as specified by |
| public final long | Returns: the valueReturns the current value, with memory semantics of reading as if the
variable was declared non- |
| public final long | Returns: the updated valueAtomically increments the current value,
with memory effects as specified by |
| public int | intValue()
Implements abstract java. Returns the current value of this |
| public final void | lazySet(long
the new value newValue)Sets the value to |
| public long | longValue()
Implements abstract java. Returns the current value of this |
| public final void | set(long
the new value newValue)Sets the value to |
| public final void | setOpaque(long
the new value newValue)Sets the value to |
| public final void | setPlain(long
the new value newValue)Sets the value to |
| public final void | setRelease(long
the new value newValue)Sets the value to |
| public String | Returns: the String representation of the current valueOverrides java. Returns the String representation of the current value. |
| public final long | Returns: the updated valuea side-effect-free function updateFunction)Atomically updates (with memory effects as specified by |
| public final boolean | Returns: true if successfulthe expected value expectedValue, long the new value newValue)
Deprecated
since 9. This method has plain memory effects but the method
name implies volatile memory effects (see methods such as
compareAndExchange and compareAndSet).
Possibly atomically sets the value to |
| public final boolean | Returns: true if successfulthe expected value expectedValue, long the new value newValue)Possibly atomically sets the value to |
| public final boolean | Returns: true if successfulthe expected value expectedValue, long the new value newValue)Possibly atomically sets the value to |
| public final boolean | Returns: true if successfulthe expected value expectedValue, long the new value newValue)Possibly atomically sets the value to |
| public final boolean | Returns: true if successfulthe expected value expectedValue, long the new value newValue)Possibly atomically sets the value to |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| U | back to summary |
|---|---|
| private static final Unsafe U | |
| VALUE | back to summary |
|---|---|
| private static final long VALUE | |
| value | back to summary |
|---|---|
| private volatile long value | |
| AtomicLong | back to summary |
|---|---|
| public AtomicLong(long initialValue) Creates a new AtomicLong with the given initial value.
| |
| AtomicLong | back to summary |
|---|---|
| public AtomicLong() Creates a new AtomicLong with initial value | |
| accumulateAndGet | back to summary |
|---|---|
| public final long accumulateAndGet(long x, LongBinaryOperator accumulatorFunction) Atomically updates (with memory effects as specified by
| |
| addAndGet | back to summary |
|---|---|
| public final long addAndGet(long delta) Atomically adds the given value to the current value,
with memory effects as specified by
| |
| compareAndExchange | back to summary |
|---|---|
| public final long compareAndExchange(long expectedValue, long newValue) Atomically sets the value to
| |
| compareAndExchangeAcquire | back to summary |
|---|---|
| public final long compareAndExchangeAcquire(long expectedValue, long newValue) Atomically sets the value to
| |
| compareAndExchangeRelease | back to summary |
|---|---|
| public final long compareAndExchangeRelease(long expectedValue, long newValue) Atomically sets the value to
| |
| compareAndSet | back to summary |
|---|---|
| public final boolean compareAndSet(long expectedValue, long newValue) Atomically sets the value to
| |
| decrementAndGet | back to summary |
|---|---|
| public final long decrementAndGet() Atomically decrements the current value,
with memory effects as specified by Equivalent to
| |
| doubleValue | back to summary |
|---|---|
| public double doubleValue() Implements abstract java. Returns the current value of this
| |
| floatValue | back to summary |
|---|---|
| public float floatValue() Implements abstract java. Returns the current value of this
| |
| get | back to summary |
|---|---|
| public final long get() Returns the current value,
with memory effects as specified by
| |
| getAcquire | back to summary |
|---|---|
| public final long getAcquire() Returns the current value,
with memory effects as specified by
| |
| getAndAccumulate | back to summary |
|---|---|
| public final long getAndAccumulate(long x, LongBinaryOperator accumulatorFunction) Atomically updates (with memory effects as specified by
| |
| getAndAdd | back to summary |
|---|---|
| public final long getAndAdd(long delta) Atomically adds the given value to the current value,
with memory effects as specified by
| |
| getAndDecrement | back to summary |
|---|---|
| public final long getAndDecrement() Atomically decrements the current value,
with memory effects as specified by Equivalent to
| |
| getAndIncrement | back to summary |
|---|---|
| public final long getAndIncrement() Atomically increments the current value,
with memory effects as specified by Equivalent to
| |
| getAndSet | back to summary |
|---|---|
| public final long getAndSet(long newValue) Atomically sets the value to
| |
| getAndUpdate | back to summary |
|---|---|
| public final long getAndUpdate(LongUnaryOperator updateFunction) Atomically updates (with memory effects as specified by
| |
| getOpaque | back to summary |
|---|---|
| public final long getOpaque() Returns the current value,
with memory effects as specified by
| |
| getPlain | back to summary |
|---|---|
| public final long getPlain() Returns the current value, with memory semantics of reading as if the
variable was declared non-
| |
| incrementAndGet | back to summary |
|---|---|
| public final long incrementAndGet() Atomically increments the current value,
with memory effects as specified by Equivalent to
| |
| intValue | back to summary |
|---|---|
| public int intValue() Implements abstract java. Returns the current value of this
| |
| lazySet | back to summary |
|---|---|
| public final void lazySet(long newValue) Sets the value to
| |
| longValue | back to summary |
|---|---|
| public long longValue() Implements abstract java. Returns the current value of this | |
| set | back to summary |
|---|---|
| public final void set(long newValue) Sets the value to
| |
| setOpaque | back to summary |
|---|---|
| public final void setOpaque(long newValue) Sets the value to
| |
| setPlain | back to summary |
|---|---|
| public final void setPlain(long newValue) Sets the value to
| |
| setRelease | back to summary |
|---|---|
| public final void setRelease(long newValue) Sets the value to
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns the String representation of the current value.
| |
| updateAndGet | back to summary |
|---|---|
| public final long updateAndGet(LongUnaryOperator updateFunction) Atomically updates (with memory effects as specified by
| |
| weakCompareAndSet | back to summary |
|---|---|
| public final boolean weakCompareAndSet(long expectedValue, long newValue)
Deprecated since 9. This method has plain memory effects but the method
name implies volatile memory effects (see methods such as
Possibly atomically sets the value to
| |
| weakCompareAndSetAcquire | back to summary |
|---|---|
| public final boolean weakCompareAndSetAcquire(long expectedValue, long newValue) Possibly atomically sets the value to
| |
| weakCompareAndSetPlain | back to summary |
|---|---|
| public final boolean weakCompareAndSetPlain(long expectedValue, long newValue) Possibly atomically sets the value to
| |
| weakCompareAndSetRelease | back to summary |
|---|---|
| public final boolean weakCompareAndSetRelease(long expectedValue, long newValue) Possibly atomically sets the value to
| |
| weakCompareAndSetVolatile | back to summary |
|---|---|
| public final boolean weakCompareAndSetVolatile(long expectedValue, long newValue) Possibly atomically sets the value to
| |