public class AtomicReferenceArray
extends java.lang.Object
implements java.io.Serializable
edu.emory.mathcs.backport.java.util.concurrent.atomic
package
specification for description of the properties of atomic
variables.Constructor and Description |
---|
AtomicReferenceArray(int length)
Creates a new AtomicReferenceArray of given length.
|
AtomicReferenceArray(java.lang.Object[] array)
Creates a new AtomicReferenceArray with the same length as, and
all elements copied from, the given array.
|
Modifier and Type | Method and Description |
---|---|
boolean |
compareAndSet(int i,
java.lang.Object expect,
java.lang.Object update)
Atomically sets the element at position
i to the given
updated value if the current value == the expected value. |
java.lang.Object |
get(int i)
Gets the current value at position
i . |
java.lang.Object |
getAndSet(int i,
java.lang.Object newValue)
Atomically sets the element at position
i to the given
value and returns the old value. |
void |
lazySet(int i,
java.lang.Object newValue)
Eventually sets the element at position
i to the given value. |
int |
length()
Returns the length of the array.
|
void |
set(int i,
java.lang.Object newValue)
Sets the element at position
i to the given value. |
java.lang.String |
toString()
Returns the String representation of the current values of array.
|
boolean |
weakCompareAndSet(int i,
java.lang.Object expect,
java.lang.Object update)
Atomically sets the element at position
i to the given
updated value if the current value == the expected value. |
public AtomicReferenceArray(int length)
length
- the length of the arraypublic AtomicReferenceArray(java.lang.Object[] array)
array
- the array to copy elements fromjava.lang.NullPointerException
- if array is nullpublic final int length()
public final java.lang.Object get(int i)
i
.i
- the indexpublic final void set(int i, java.lang.Object newValue)
i
to the given value.i
- the indexnewValue
- the new valuepublic final void lazySet(int i, java.lang.Object newValue)
i
to the given value.i
- the indexnewValue
- the new valuepublic final java.lang.Object getAndSet(int i, java.lang.Object newValue)
i
to the given
value and returns the old value.i
- the indexnewValue
- the new valuepublic final boolean compareAndSet(int i, java.lang.Object expect, java.lang.Object update)
i
to the given
updated value if the current value ==
the expected value.i
- the indexexpect
- the expected valueupdate
- the new valuepublic final boolean weakCompareAndSet(int i, java.lang.Object expect, java.lang.Object update)
i
to 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
.
i
- the indexexpect
- the expected valueupdate
- the new valuepublic java.lang.String toString()
toString
in class java.lang.Object