Class AtomicBoolean
java.lang.Object
java.util.concurrent.atomic.AtomicBoolean
- All Implemented Interfaces:
Serializable
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newAtomicBooleanwith initial valuefalse.AtomicBoolean(boolean initialValue) Creates a newAtomicBooleanwith the given initial value. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleancompareAndExchange(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchange(Object...).final booleancompareAndExchangeAcquire(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchangeAcquire(Object...).final booleancompareAndExchangeRelease(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchangeRelease(Object...).final booleancompareAndSet(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.compareAndSet(Object...).final booleanget()Returns the current value, with memory effects as specified byVarHandle.getVolatile(Object...).final booleanReturns the current value, with memory effects as specified byVarHandle.getAcquire(Object...).final booleangetAndSet(boolean newValue) Atomically sets the value tonewValueand returns the old value, with memory effects as specified byVarHandle.getAndSet(Object...).final booleanReturns the current value, with memory effects as specified byVarHandle.getOpaque(Object...).final booleangetPlain()Returns the current value, with memory semantics of reading as if the variable was declared non-volatile.final voidlazySet(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setRelease(Object...).final voidset(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setVolatile(Object...).final voidsetOpaque(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setOpaque(Object...).final voidsetPlain(boolean newValue) Sets the value tonewValue, with memory semantics of setting as if the variable was declared non-volatileand non-final.final voidsetRelease(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setRelease(Object...).toString()Returns the String representation of the current value.booleanweakCompareAndSet(boolean expectedValue, boolean newValue) Deprecated.final booleanweakCompareAndSetAcquire(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetAcquire(Object...).booleanweakCompareAndSetPlain(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetPlain(Object...).final booleanweakCompareAndSetRelease(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetRelease(Object...).final booleanweakCompareAndSetVolatile(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSet(Object...).Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
AtomicBoolean
public AtomicBoolean(boolean initialValue) Creates a newAtomicBooleanwith the given initial value.- Parameters:
initialValue- the initial value
-
AtomicBoolean
public AtomicBoolean()Creates a newAtomicBooleanwith initial valuefalse.
-
-
Method Details
-
get
public final boolean get()Returns the current value, with memory effects as specified byVarHandle.getVolatile(Object...).- Returns:
- the current value
-
compareAndSet
public final boolean compareAndSet(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.compareAndSet(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful. False return indicates that the actual value was not equal to the expected value.
-
weakCompareAndSet
Deprecated.This method has plain memory effects but the method name implies volatile memory effects (see methods such ascompareAndExchange(boolean, boolean)andcompareAndSet(boolean, boolean)). To avoid confusion over plain or volatile memory effects it is recommended that the methodweakCompareAndSetPlain(boolean, boolean)be used instead.Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetPlain(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful- See Also:
-
weakCompareAndSetPlain
public boolean weakCompareAndSetPlain(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetPlain(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful- Since:
- 9
-
set
public final void set(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setVolatile(Object...).- Parameters:
newValue- the new value
-
lazySet
public final void lazySet(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setRelease(Object...).- Parameters:
newValue- the new value- Since:
- 1.6
-
getAndSet
public final boolean getAndSet(boolean newValue) Atomically sets the value tonewValueand returns the old value, with memory effects as specified byVarHandle.getAndSet(Object...).- Parameters:
newValue- the new value- Returns:
- the previous value
-
toString
-
getPlain
public final boolean getPlain()Returns the current value, with memory semantics of reading as if the variable was declared non-volatile.- Returns:
- the value
- Since:
- 9
-
setPlain
public final void setPlain(boolean newValue) Sets the value tonewValue, with memory semantics of setting as if the variable was declared non-volatileand non-final.- Parameters:
newValue- the new value- Since:
- 9
-
getOpaque
public final boolean getOpaque()Returns the current value, with memory effects as specified byVarHandle.getOpaque(Object...).- Returns:
- the value
- Since:
- 9
-
setOpaque
public final void setOpaque(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setOpaque(Object...).- Parameters:
newValue- the new value- Since:
- 9
-
getAcquire
public final boolean getAcquire()Returns the current value, with memory effects as specified byVarHandle.getAcquire(Object...).- Returns:
- the value
- Since:
- 9
-
setRelease
public final void setRelease(boolean newValue) Sets the value tonewValue, with memory effects as specified byVarHandle.setRelease(Object...).- Parameters:
newValue- the new value- Since:
- 9
-
compareAndExchange
public final boolean compareAndExchange(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchange(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
- Since:
- 9
-
compareAndExchangeAcquire
public final boolean compareAndExchangeAcquire(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchangeAcquire(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
- Since:
- 9
-
compareAndExchangeRelease
public final boolean compareAndExchangeRelease(boolean expectedValue, boolean newValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue, with memory effects as specified byVarHandle.compareAndExchangeRelease(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
- Since:
- 9
-
weakCompareAndSetVolatile
public final boolean weakCompareAndSetVolatile(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSet(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful- Since:
- 9
-
weakCompareAndSetAcquire
public final boolean weakCompareAndSetAcquire(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetAcquire(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful- Since:
- 9
-
weakCompareAndSetRelease
public final boolean weakCompareAndSetRelease(boolean expectedValue, boolean newValue) Possibly atomically sets the value tonewValueif the current value== expectedValue, with memory effects as specified byVarHandle.weakCompareAndSetRelease(Object...).- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful- Since:
- 9
-
compareAndExchange(boolean, boolean)andcompareAndSet(boolean, boolean)).