java.util.concurrent.atomic.AtomicReferenceArrayThe class provides an operation of the underlying reference array that can be read and written by Atoms, and also contains advanced atomic operations. AtomicReferenceArraysupports atomic manipulation of the underlying reference array variable. It has a get and set method, such as read and write on a variable. In other words, a collection is associated with any subsequent fetch on the same variable. Atomic compareAndSet methods also have these memory-consistency features.
Atomicreferencearray Method
The following is a AtomicReferenceArray list of the important methods available in the class.
| sequence |
Method |
Description |
| 1 |
public boolean compareAndSet(int i, E expect, E update) |
If the current value is == expected, the i element atom at the location is set to the given update value. |
| 2 |
public E get(int i) |
Gets i The current value of the position. |
| 3 |
public E getAndSet(int i, E newValue) |
isets the atom of the element at the location to the given value and returns the old value. |
| 4 |
public void lazySet(int i, E newValue) |
Finally, the i element at the location is set to the given value. |
| 5 |
public int length() |
Returns the length of the array. |
| 6 |
public void set(int i, E newValue) |
isets the element at the location to the given value. |
| 7 |
public String toString() |
Returns the representation of the current value of the array String . |
| 8 |
public boolean weakCompareAndSet(int i, E expect, E update) |
If the current value is == expected, the i element atom at the location is set to the given update value. |
Example
Click on the link to view the details
Java Concurrency Atomicreferencearray class