Java atomicintegerarray
AtomicIntegerArray
is a class in Java's java.util.concurrent.atomic
package that provides atomic operations on arrays of integers. An atomic operation is an operation that is performed as a single, indivisible unit of execution, which means that it appears to occur instantaneously and cannot be interrupted by other operations.
The AtomicIntegerArray
class provides the following atomic operations on arrays of integers:
get(int index)
: Returns the value of the element at the specified index.set(int index, int newValue)
: Sets the value of the element at the specified index to the specified new value.getAndSet(int index, int newValue)
: Atomically sets the value of the element at the specified index to the specified new value and returns the previous value.compareAndSet(int index, int expect, int update)
: Atomically sets the value of the element at the specified index to the specified new value if the current value equals the expected value, and returns true if the update was successful.incrementAndGet(int index)
: Atomically increments by one the value of the element at the specified index and returns the updated value.decrementAndGet(int index)
: Atomically decrements by one the value of the element at the specified index and returns the updated value.addAndGet(int index, int delta)
: Atomically adds the specified delta to the value of the element at the specified index and returns the updated value.
These operations are useful for implementing thread-safe algorithms that require access to shared data. The AtomicIntegerArray
class is especially useful for implementing lock-free data structures and algorithms that require high-performance concurrent access to arrays of integers.