java.util.concurrent.atomic
Class AtomicReferenceArray<E>

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.concurrent.atomic.AtomicReferenceArray<E>
Type Parameters:
E - The base class of elements held in this array
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public class AtomicReferenceArray<E>
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Serializable sample code for java.io.Serializable definition code for java.io.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
See Also:
Serialized Form

Constructor Summary
AtomicReferenceArray sample code for java.util.concurrent.atomic.AtomicReferenceArray.AtomicReferenceArray(E[]) definition code for java.util.concurrent.atomic.AtomicReferenceArray.AtomicReferenceArray(E[]) (E[] array)
          Create a new AtomicReferenceArray with the same length as, and all elements copied from, the given array.
AtomicReferenceArray sample code for java.util.concurrent.atomic.AtomicReferenceArray.AtomicReferenceArray(int) definition code for java.util.concurrent.atomic.AtomicReferenceArray.AtomicReferenceArray(int) (int length)
          Create a new AtomicReferenceArray of given length.
 
Method Summary
 boolean compareAndSet sample code for java.util.concurrent.atomic.AtomicReferenceArray.compareAndSet(int, E, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.compareAndSet(int, E, E) (int i, E expect, E update)
          Atomically set the value to the given updated value if the current value == the expected value.
 E get sample code for java.util.concurrent.atomic.AtomicReferenceArray.get(int) definition code for java.util.concurrent.atomic.AtomicReferenceArray.get(int) (int i)
          Get the current value at position i.
 E getAndSet sample code for java.util.concurrent.atomic.AtomicReferenceArray.getAndSet(int, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.getAndSet(int, E) (int i, E newValue)
          Set the element at position i to the given value and return the old value.
 int length sample code for java.util.concurrent.atomic.AtomicReferenceArray.length() definition code for java.util.concurrent.atomic.AtomicReferenceArray.length() ()
          Returns the length of the array.
 void set sample code for java.util.concurrent.atomic.AtomicReferenceArray.set(int, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.set(int, E) (int i, E newValue)
          Set the element at position i to the given value.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.util.concurrent.atomic.AtomicReferenceArray.toString() definition code for java.util.concurrent.atomic.AtomicReferenceArray.toString() ()
          Returns the String representation of the current values of array.
 boolean weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicReferenceArray.weakCompareAndSet(int, E, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.weakCompareAndSet(int, E, E) (int i, E expect, E update)
          Atomically set the value to the given updated value if the current value == the expected value.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

AtomicReferenceArray sample code for java.util.concurrent.atomic.AtomicReferenceArray(int) definition code for java.util.concurrent.atomic.AtomicReferenceArray(int)

public AtomicReferenceArray(int length)
Create a new AtomicReferenceArray of given length.

Parameters:
length - the length of the array

AtomicReferenceArray sample code for java.util.concurrent.atomic.AtomicReferenceArray(E[]) definition code for java.util.concurrent.atomic.AtomicReferenceArray(E[])

public AtomicReferenceArray(E[] array)
Create 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 sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if array is null
Method Detail

length sample code for java.util.concurrent.atomic.AtomicReferenceArray.length() definition code for java.util.concurrent.atomic.AtomicReferenceArray.length()

public final int length()
Returns the length of the array.

Returns:
the length of the array

get sample code for java.util.concurrent.atomic.AtomicReferenceArray.get(int) definition code for java.util.concurrent.atomic.AtomicReferenceArray.get(int)

public final E get(int i)
Get the current value at position i.

Parameters:
i - the index
Returns:
the current value

set sample code for java.util.concurrent.atomic.AtomicReferenceArray.set(int, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.set(int, E)

public final void set(int i,
                      E newValue)
Set the element at position i to the given value.

Parameters:
i - the index
newValue - the new value

getAndSet sample code for java.util.concurrent.atomic.AtomicReferenceArray.getAndSet(int, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.getAndSet(int, E)

public final E getAndSet(int i,
                         E newValue)
Set the element at position i to the given value and return the old value.

Parameters:
i - the index
newValue - the new value
Returns:
the previous value

compareAndSet sample code for java.util.concurrent.atomic.AtomicReferenceArray.compareAndSet(int, E, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.compareAndSet(int, E, E)

public final boolean compareAndSet(int i,
                                   E expect,
                                   E update)
Atomically set the value to the given updated value if the current value == the expected value.

Parameters:
i - the index
expect - the expected value
update - the new value
Returns:
true if successful. False return indicates that the actual value was not equal to the expected value.

weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicReferenceArray.weakCompareAndSet(int, E, E) definition code for java.util.concurrent.atomic.AtomicReferenceArray.weakCompareAndSet(int, E, E)

public final boolean weakCompareAndSet(int i,
                                       E expect,
                                       E update)
Atomically set the value to the given updated value if the current value == the expected value. May fail spuriously.

Parameters:
i - the index
expect - the expected value
update - the new value
Returns:
true if successful.

toString sample code for java.util.concurrent.atomic.AtomicReferenceArray.toString() definition code for java.util.concurrent.atomic.AtomicReferenceArray.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns the String representation of the current values of array.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the String representation of the current values of array.