java.util.concurrent.atomic
Class AtomicReference<V>

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.concurrent.atomic.AtomicReference<V>
Type Parameters:
V - The type of object referred to by this reference
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public class AtomicReference<V>
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 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 sample code for java.util.concurrent.atomic.AtomicReference.AtomicReference() definition code for java.util.concurrent.atomic.AtomicReference.AtomicReference() ()
          Create a new AtomicReference with null initial value.
AtomicReference sample code for java.util.concurrent.atomic.AtomicReference.AtomicReference(V) definition code for java.util.concurrent.atomic.AtomicReference.AtomicReference(V) (V initialValue)
          Create a new AtomicReference with the given initial value.
 
Method Summary
 boolean compareAndSet sample code for java.util.concurrent.atomic.AtomicReference.compareAndSet(V, V) definition code for java.util.concurrent.atomic.AtomicReference.compareAndSet(V, V) (V expect, V update)
          Atomically set the value to the given updated value if the current value == the expected value.
 V get sample code for java.util.concurrent.atomic.AtomicReference.get() definition code for java.util.concurrent.atomic.AtomicReference.get() ()
          Get the current value.
 V getAndSet sample code for java.util.concurrent.atomic.AtomicReference.getAndSet(V) definition code for java.util.concurrent.atomic.AtomicReference.getAndSet(V) (V newValue)
          Set to the given value and return the old value.
 void set sample code for java.util.concurrent.atomic.AtomicReference.set(V) definition code for java.util.concurrent.atomic.AtomicReference.set(V) (V newValue)
          Set 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.AtomicReference.toString() definition code for java.util.concurrent.atomic.AtomicReference.toString() ()
          Returns the String representation of the current value.
 boolean weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicReference.weakCompareAndSet(V, V) definition code for java.util.concurrent.atomic.AtomicReference.weakCompareAndSet(V, V) (V expect, V 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

AtomicReference sample code for java.util.concurrent.atomic.AtomicReference(V) definition code for java.util.concurrent.atomic.AtomicReference(V)

public AtomicReference(V initialValue)
Create a new AtomicReference with the given initial value.

Parameters:
initialValue - the initial value

AtomicReference sample code for java.util.concurrent.atomic.AtomicReference() definition code for java.util.concurrent.atomic.AtomicReference()

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

Method Detail

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

public final V get()
Get the current value.

Returns:
the current value

set sample code for java.util.concurrent.atomic.AtomicReference.set(V) definition code for java.util.concurrent.atomic.AtomicReference.set(V)

public final void set(V newValue)
Set to the given value.

Parameters:
newValue - the new value

compareAndSet sample code for java.util.concurrent.atomic.AtomicReference.compareAndSet(V, V) definition code for java.util.concurrent.atomic.AtomicReference.compareAndSet(V, V)

public final boolean compareAndSet(V expect,
                                   V 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 sample code for java.util.concurrent.atomic.AtomicReference.weakCompareAndSet(V, V) definition code for java.util.concurrent.atomic.AtomicReference.weakCompareAndSet(V, V)

public final boolean weakCompareAndSet(V expect,
                                       V 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 sample code for java.util.concurrent.atomic.AtomicReference.getAndSet(V) definition code for java.util.concurrent.atomic.AtomicReference.getAndSet(V)

public final V getAndSet(V newValue)
Set to the given value and return the old value.

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

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

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

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 value.