An {@code int} value that may be updated atomically. See the
package specification for
description of the properties of atomic variables. An
{@code AtomicInteger} is used in applications such as atomically
incremented counters, and cannot be used as a replacement for an
. However, this class does extend
{@code Number} to allow uniform access by tools and utilities that
deal with numerically-based classes.
| Method from java.util.concurrent.atomic.AtomicInteger Detail: |
public final int addAndGet(int delta) {
for (;;) {
int current = get();
int next = current + delta;
if (compareAndSet(current, next))
return next;
}
}
Atomically adds the given value to the current value. |
public final boolean compareAndSet(int expect,
int update) {
return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
}
Atomically sets the value to the given updated value
if the current value {@code ==} the expected value. |
public final int decrementAndGet() {
for (;;) {
int current = get();
int next = current - 1;
if (compareAndSet(current, next))
return next;
}
}
Atomically decrements by one the current value. |
public double doubleValue() {
return (double)get();
}
|
public float floatValue() {
return (float)get();
}
|
public final int get() {
return value;
}
|
public final int getAndAdd(int delta) {
for (;;) {
int current = get();
int next = current + delta;
if (compareAndSet(current, next))
return current;
}
}
Atomically adds the given value to the current value. |
public final int getAndDecrement() {
for (;;) {
int current = get();
int next = current - 1;
if (compareAndSet(current, next))
return current;
}
}
Atomically decrements by one the current value. |
public final int getAndIncrement() {
for (;;) {
int current = get();
int next = current + 1;
if (compareAndSet(current, next))
return current;
}
}
Atomically increments by one the current value. |
public final int getAndSet(int newValue) {
for (;;) {
int current = get();
if (compareAndSet(current, newValue))
return current;
}
}
Atomically sets to the given value and returns the old value. |
public final int incrementAndGet() {
for (;;) {
int current = get();
int next = current + 1;
if (compareAndSet(current, next))
return next;
}
}
Atomically increments by one the current value. |
public int intValue() {
return get();
}
|
public final void lazySet(int newValue) {
unsafe.putOrderedInt(this, valueOffset, newValue);
}
Eventually sets to the given value. |
public long longValue() {
return (long)get();
}
|
public final void set(int newValue) {
value = newValue;
}
|
public String toString() {
return Integer.toString(get());
}
Returns the String representation of the current value. |
public final boolean weakCompareAndSet(int expect,
int update) {
return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
}
Atomically sets the value to the given updated value
if the current value {@code ==} the expected value.
May fail spuriously
and does not provide ordering guarantees, so is only rarely an
appropriate alternative to {@code compareAndSet}. |