Package java.util.concurrent.atomic
Class AtomicReferenceArray<E>
java.lang.Object
java.util.concurrent.atomic.AtomicReferenceArray<E>
- Type Parameters:
E- The base class of elements held in this array
- All Implemented Interfaces:
Serializable
public class AtomicReferenceArray<E> extends Object implements Serializable
An array of object references in which elements may be updated
atomically. See the
java.util.concurrent.atomic package
specification for description of the properties of atomic
variables.- Since:
- 1.5
- Author:
- Doug Lea
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description AtomicReferenceArray(int length)Creates a new AtomicReferenceArray of the given length, with all elements initially null.AtomicReferenceArray(E[] array)Creates a new AtomicReferenceArray with the same length as, and all elements copied from, the given array. -
Method Summary
Modifier and Type Method Description booleancompareAndSet(int i, E expect, E update)Atomically sets the element at positionito the given updated value if the current value==the expected value.Eget(int i)Gets the current value at positioni.EgetAndSet(int i, E newValue)Atomically sets the element at positionito the given value and returns the old value.voidlazySet(int i, E newValue)Eventually sets the element at positionito the given value.intlength()Returns the length of the array.voidset(int i, E newValue)Sets the element at positionito the given value.StringtoString()Returns the String representation of the current values of array.booleanweakCompareAndSet(int i, E expect, E update)Atomically sets the element at positionito the given updated value if the current value==the expected value.
-
Constructor Details
-
AtomicReferenceArray
public AtomicReferenceArray(int length)Creates a new AtomicReferenceArray of the given length, with all elements initially null.- Parameters:
length- the length of the array
-
AtomicReferenceArray
Creates a new AtomicReferenceArray with the same length as, and all elements copied from, the given array.- Parameters:
array- the array to copy elements from- Throws:
NullPointerException- if array is null
-
-
Method Details
-
length
public final int length()Returns the length of the array.- Returns:
- the length of the array
-
get
Gets the current value at positioni.- Parameters:
i- the index- Returns:
- the current value
-
set
Sets the element at positionito the given value.- Parameters:
i- the indexnewValue- the new value
-
lazySet
Eventually sets the element at positionito the given value.- Parameters:
i- the indexnewValue- the new value- Since:
- 1.6
-
getAndSet
Atomically sets the element at positionito the given value and returns the old value.- Parameters:
i- the indexnewValue- the new value- Returns:
- the previous value
-
compareAndSet
Atomically sets the element at positionito the given updated value if the current value==the expected value.- Parameters:
i- the indexexpect- the expected valueupdate- the new value- Returns:
- true if successful. False return indicates that the actual value was not equal to the expected value.
-
weakCompareAndSet
Atomically sets the element at positionito the given updated value if the current value==the expected value.May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to
compareAndSet.- Parameters:
i- the indexexpect- the expected valueupdate- the new value- Returns:
- true if successful
-
toString
Returns the String representation of the current values of array.
-