java.util.concurrent.atomic
Class AtomicBoolean

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.concurrent.atomic.AtomicBoolean
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public class AtomicBoolean
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

A boolean value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables. An AtomicBoolean is used in applications such as atomically updated flags, and cannot be used as a replacement for a Boolean sample code for java.lang.Boolean definition code for java.lang.Boolean .

Since:
1.5
See Also:
Serialized Form

Constructor Summary
AtomicBoolean sample code for java.util.concurrent.atomic.AtomicBoolean.AtomicBoolean() definition code for java.util.concurrent.atomic.AtomicBoolean.AtomicBoolean() ()
          Creates a new AtomicBoolean with initial value false.
AtomicBoolean sample code for java.util.concurrent.atomic.AtomicBoolean.AtomicBoolean(boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.AtomicBoolean(boolean) (boolean initialValue)
          Creates a new AtomicBoolean with the given initial value.
 
Method Summary
 boolean compareAndSet sample code for java.util.concurrent.atomic.AtomicBoolean.compareAndSet(boolean, boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.compareAndSet(boolean, boolean) (boolean expect, boolean update)
          Atomically set the value to the given updated value if the current value == the expected value.
 boolean get sample code for java.util.concurrent.atomic.AtomicBoolean.get() definition code for java.util.concurrent.atomic.AtomicBoolean.get() ()
          Returns the current value.
 boolean getAndSet sample code for java.util.concurrent.atomic.AtomicBoolean.getAndSet(boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.getAndSet(boolean) (boolean newValue)
          Sets to the given value and returns the previous value.
 void set sample code for java.util.concurrent.atomic.AtomicBoolean.set(boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.set(boolean) (boolean newValue)
          Unconditionally sets 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.AtomicBoolean.toString() definition code for java.util.concurrent.atomic.AtomicBoolean.toString() ()
          Returns the String representation of the current value.
 boolean weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicBoolean.weakCompareAndSet(boolean, boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.weakCompareAndSet(boolean, boolean) (boolean expect, boolean 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

AtomicBoolean sample code for java.util.concurrent.atomic.AtomicBoolean(boolean) definition code for java.util.concurrent.atomic.AtomicBoolean(boolean)

public AtomicBoolean(boolean initialValue)
Creates a new AtomicBoolean with the given initial value.

Parameters:
initialValue - the initial value

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

public AtomicBoolean()
Creates a new AtomicBoolean with initial value false.

Method Detail

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

public final boolean get()
Returns the current value.

Returns:
the current value

compareAndSet sample code for java.util.concurrent.atomic.AtomicBoolean.compareAndSet(boolean, boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.compareAndSet(boolean, boolean)

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

public boolean weakCompareAndSet(boolean expect,
                                 boolean 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.

set sample code for java.util.concurrent.atomic.AtomicBoolean.set(boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.set(boolean)

public final void set(boolean newValue)
Unconditionally sets to the given value.

Parameters:
newValue - the new value

getAndSet sample code for java.util.concurrent.atomic.AtomicBoolean.getAndSet(boolean) definition code for java.util.concurrent.atomic.AtomicBoolean.getAndSet(boolean)

public final boolean getAndSet(boolean newValue)
Sets to the given value and returns the previous value.

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

toString sample code for java.util.concurrent.atomic.AtomicBoolean.toString() definition code for java.util.concurrent.atomic.AtomicBoolean.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.