int value that may be updated atomically. See the
VarHandle specification for descriptions of the properties
of atomic accesses. An AtomicInteger is used in
applications such as atomically incremented counters, and cannot be
used as a replacement for an java.lang.Integer . 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 int |
| Access | Constructor and Description |
|---|---|
| public | AtomicInteger(int
the initial value initialValue)Creates a new AtomicInteger with the given initial value. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final int | Returns: the updated valuethe update value x, IntBinaryOperator a side-effect-free function of two arguments accumulatorFunction)Atomically updates (with memory effects as specified by |
| public final int | 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 int | Returns: the witness value, which will be the same as the expected value if successfulthe expected value expectedValue, int the new value newValue)Atomically sets the value to |
| public final int | Returns: the witness value, which will be the same as the expected value if successfulthe expected value expectedValue, int the new value newValue)Atomically sets the value to |
| public final int | Returns: the witness value, which will be the same as the expected value if successfulthe expected value expectedValue, int 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, int the new value newValue)Atomically sets the value to |
| public final int | 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 int | Returns: the current valueReturns the current value,
with memory effects as specified by |
| public final int | Returns: the valueReturns the current value,
with memory effects as specified by |
| public final int | Returns: the previous valuethe update value x, IntBinaryOperator a side-effect-free function of two arguments accumulatorFunction)Atomically updates (with memory effects as specified by |
| public final int | 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 int | Returns: the previous valueAtomically decrements the current value,
with memory effects as specified by |
| public final int | Returns: the previous valueAtomically increments the current value,
with memory effects as specified by |
| public final int | Returns: the previous valuethe new value newValue)Atomically sets the value to |
| public final int | Returns: the previous valuea side-effect-free function updateFunction)Atomically updates (with memory effects as specified by |
| public final int | Returns: the valueReturns the current value,
with memory effects as specified by |
| public final int | Returns: the valueReturns the current value, with memory semantics of reading as
if the variable was declared non- |
| public final int | 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(int
the new value newValue)Sets the value to |
| public long | longValue()
Implements abstract java. Returns the current value of this |
| public final void | set(int
the new value newValue)Sets the value to |
| public final void | setOpaque(int
the new value newValue)Sets the value to |
| public final void | setPlain(int
the new value newValue)Sets the value to |
| public final void | setRelease(int
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 int | 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, int 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, int the new value newValue)Possibly atomically sets the value to |
| public final boolean | Returns: true if successfulthe expected value expectedValue, int the new value newValue)Possibly atomically sets the value to |
| public final boolean | Returns: true if successfulthe expected value expectedValue, int the new value newValue)Possibly atomically sets the value to |
| public final boolean | Returns: true if successfulthe expected value expectedValue, int 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 int value | |
| AtomicInteger | back to summary |
|---|---|
| public AtomicInteger(int initialValue) Creates a new AtomicInteger with the given initial value.
| |
| AtomicInteger | back to summary |
|---|---|
| public AtomicInteger() Creates a new AtomicInteger with initial value | |
| accumulateAndGet | back to summary |
|---|---|
| public final int accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) Atomically updates (with memory effects as specified by
| |
| addAndGet | back to summary |
|---|---|
| public final int addAndGet(int delta) Atomically adds the given value to the current value,
with memory effects as specified by
| |
| compareAndExchange | back to summary |
|---|---|
| public final int compareAndExchange(int expectedValue, int newValue) Atomically sets the value to
| |
| compareAndExchangeAcquire | back to summary |
|---|---|
| public final int compareAndExchangeAcquire(int expectedValue, int newValue) Atomically sets the value to
| |
| compareAndExchangeRelease | back to summary |
|---|---|
| public final int compareAndExchangeRelease(int expectedValue, int newValue) Atomically sets the value to
| |
| compareAndSet | back to summary |
|---|---|
| public final boolean compareAndSet(int expectedValue, int newValue) Atomically sets the value to
| |
| decrementAndGet | back to summary |
|---|---|
| public final int 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 int get() Returns the current value,
with memory effects as specified by
| |
| getAcquire | back to summary |
|---|---|
| public final int getAcquire() Returns the current value,
with memory effects as specified by
| |
| getAndAccumulate | back to summary |
|---|---|
| public final int getAndAccumulate(int x, IntBinaryOperator accumulatorFunction) Atomically updates (with memory effects as specified by
| |
| getAndAdd | back to summary |
|---|---|
| public final int getAndAdd(int delta) Atomically adds the given value to the current value,
with memory effects as specified by
| |
| getAndDecrement | back to summary |
|---|---|
| public final int getAndDecrement() Atomically decrements the current value,
with memory effects as specified by Equivalent to
| |
| getAndIncrement | back to summary |
|---|---|
| public final int getAndIncrement() Atomically increments the current value,
with memory effects as specified by Equivalent to
| |
| getAndSet | back to summary |
|---|---|
| public final int getAndSet(int newValue) Atomically sets the value to
| |
| getAndUpdate | back to summary |
|---|---|
| public final int getAndUpdate(IntUnaryOperator updateFunction) Atomically updates (with memory effects as specified by
| |
| getOpaque | back to summary |
|---|---|
| public final int getOpaque() Returns the current value,
with memory effects as specified by
| |
| getPlain | back to summary |
|---|---|
| public final int getPlain() Returns the current value, with memory semantics of reading as
if the variable was declared non-
| |
| incrementAndGet | back to summary |
|---|---|
| public final int 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(int 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(int newValue) Sets the value to
| |
| setOpaque | back to summary |
|---|---|
| public final void setOpaque(int newValue) Sets the value to
| |
| setPlain | back to summary |
|---|---|
| public final void setPlain(int newValue) Sets the value to
| |
| setRelease | back to summary |
|---|---|
| public final void setRelease(int 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 int updateAndGet(IntUnaryOperator updateFunction) Atomically updates (with memory effects as specified by
| |
| weakCompareAndSet | back to summary |
|---|---|
| public final boolean weakCompareAndSet(int expectedValue, int 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(int expectedValue, int newValue) Possibly atomically sets the value to
| |
| weakCompareAndSetPlain | back to summary |
|---|---|
| public final boolean weakCompareAndSetPlain(int expectedValue, int newValue) Possibly atomically sets the value to
| |
| weakCompareAndSetRelease | back to summary |
|---|---|
| public final boolean weakCompareAndSetRelease(int expectedValue, int newValue) Possibly atomically sets the value to
| |
| weakCompareAndSetVolatile | back to summary |
|---|---|
| public final boolean weakCompareAndSetVolatile(int expectedValue, int newValue) Possibly atomically sets the value to
| |