edu.emory.mathcs.util.concurrent.atomic
Class AtomicReference

java.lang.Object
  |
  +--edu.emory.mathcs.util.concurrent.atomic.AtomicReference
All Implemented Interfaces:
java.io.Serializable

public class AtomicReference
extends java.lang.Object
implements java.io.Serializable

An object reference that 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
AtomicReference()
          Create a new AtomicReference with null initial value.
AtomicReference(java.lang.Object initialValue)
          Create a new AtomicReference with the given initial value.
 
Method Summary
 boolean compareAndSet(java.lang.Object expect, java.lang.Object update)
          Atomically set the value to the given updated value if the current value == the expected value.
 java.lang.Object get()
          Get the current value.
 java.lang.Object getAndSet(java.lang.Object newValue)
          Set to the given value and return the old value.
 void set(java.lang.Object newValue)
          Set to the given value.
 java.lang.String toString()
          Returns the String representation of the current value.
 boolean weakCompareAndSet(java.lang.Object expect, java.lang.Object update)
          Atomically set the value to the given updated value if the current value == the expected value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AtomicReference

public AtomicReference(java.lang.Object initialValue)
Create a new AtomicReference with the given initial value.

Parameters:
initialValue - the initial value

AtomicReference

public AtomicReference()
Create a new AtomicReference with null initial value.

Method Detail

get

public final java.lang.Object get()
Get the current value.

Returns:
the current value

set

public final void set(java.lang.Object newValue)
Set to the given value.

Parameters:
newValue - the new value

compareAndSet

public final boolean compareAndSet(java.lang.Object expect,
                                   java.lang.Object update)
Atomically set the value to the given updated value if the current value == the expected value.

Parameters:
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

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

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

getAndSet

public final java.lang.Object getAndSet(java.lang.Object newValue)
Set to the given value and return the old value.

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

toString

public java.lang.String toString()
Returns the String representation of the current value.

Overrides:
toString in class java.lang.Object
Returns:
the String representation of the current value.