Serializable
public class AtomicBoolean extends Object implements Serializable
boolean
value that may be updated atomically. See the
VarHandle
specification for descriptions of the properties
of atomic accesses. An AtomicBoolean
is used in
applications such as atomically updated flags, and cannot be used
as a replacement for a Boolean
.Constructor | Description |
---|---|
AtomicBoolean() |
Creates a new
AtomicBoolean with initial value false . |
AtomicBoolean(boolean initialValue) |
Creates a new
AtomicBoolean with the given initial value. |
Modifier and Type | Method | Description |
---|---|---|
boolean |
compareAndExchange(boolean expectedValue,
boolean newValue) |
Atomically sets the value to
newValue if the current value,
referred to as the witness value, == expectedValue ,
with memory effects as specified by
VarHandle.compareAndExchange(java.lang.Object...) . |
boolean |
compareAndExchangeAcquire(boolean expectedValue,
boolean newValue) |
Atomically sets the value to
newValue if the current value,
referred to as the witness value, == expectedValue ,
with memory effects as specified by
VarHandle.compareAndExchangeAcquire(java.lang.Object...) . |
boolean |
compareAndExchangeRelease(boolean expectedValue,
boolean newValue) |
Atomically sets the value to
newValue if the current value,
referred to as the witness value, == expectedValue ,
with memory effects as specified by
VarHandle.compareAndExchangeRelease(java.lang.Object...) . |
boolean |
compareAndSet(boolean expectedValue,
boolean newValue) |
Atomically sets the value to
newValue
if the current value == expectedValue ,
with memory effects as specified by VarHandle.compareAndSet(java.lang.Object...) . |
boolean |
get() |
Returns the current value,
with memory effects as specified by
VarHandle.getVolatile(java.lang.Object...) . |
boolean |
getAcquire() |
Returns the current value,
with memory effects as specified by
VarHandle.getAcquire(java.lang.Object...) . |
boolean |
getAndSet(boolean newValue) |
Atomically sets the value to
newValue and returns the old value,
with memory effects as specified by VarHandle.getAndSet(java.lang.Object...) . |
boolean |
getOpaque() |
Returns the current value,
with memory effects as specified by
VarHandle.getOpaque(java.lang.Object...) . |
boolean |
getPlain() |
Returns the current value, with memory semantics of reading as
if the variable was declared non-
volatile . |
void |
lazySet(boolean newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...) . |
void |
set(boolean newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setVolatile(java.lang.Object...) . |
void |
setOpaque(boolean newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setOpaque(java.lang.Object...) . |
void |
setPlain(boolean newValue) |
Sets the value to
newValue , with memory semantics
of setting as if the variable was declared non-volatile
and non-final . |
void |
setRelease(boolean newValue) |
Sets the value to
newValue ,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...) . |
String |
toString() |
Returns the String representation of the current value.
|
boolean |
weakCompareAndSet(boolean expectedValue,
boolean newValue) |
Deprecated.
This method has plain memory effects but the method
name implies volatile memory effects (see methods such as
compareAndExchange(boolean, boolean) and compareAndSet(boolean, boolean) ). To avoid
confusion over plain or volatile memory effects it is recommended that
the method weakCompareAndSetPlain(boolean, boolean) be used instead. |
boolean |
weakCompareAndSetAcquire(boolean expectedValue,
boolean newValue) |
Possibly atomically sets the value to
newValue if the current
value == expectedValue ,
with memory effects as specified by
VarHandle.weakCompareAndSetAcquire(java.lang.Object...) . |
boolean |
weakCompareAndSetPlain(boolean expectedValue,
boolean newValue) |
Possibly atomically sets the value to
newValue
if the current value == expectedValue ,
with memory effects as specified by VarHandle.weakCompareAndSetPlain(java.lang.Object...) . |
boolean |
weakCompareAndSetRelease(boolean expectedValue,
boolean newValue) |
Possibly atomically sets the value to
newValue if the current
value == expectedValue ,
with memory effects as specified by
VarHandle.weakCompareAndSetRelease(java.lang.Object...) . |
boolean |
weakCompareAndSetVolatile(boolean expectedValue,
boolean newValue) |
Possibly atomically sets the value to
newValue if the current
value == expectedValue ,
with memory effects as specified by
VarHandle.weakCompareAndSet(java.lang.Object...) . |
public AtomicBoolean(boolean initialValue)
AtomicBoolean
with the given initial value.initialValue
- the initial valuepublic AtomicBoolean()
AtomicBoolean
with initial value false
.public final boolean get()
VarHandle.getVolatile(java.lang.Object...)
.public final boolean compareAndSet(boolean expectedValue, boolean newValue)
newValue
if the current value == expectedValue
,
with memory effects as specified by VarHandle.compareAndSet(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successful. False return indicates that
the actual value was not equal to the expected value.@Deprecated(since="9") public boolean weakCompareAndSet(boolean expectedValue, boolean newValue)
compareAndExchange(boolean, boolean)
and compareAndSet(boolean, boolean)
). To avoid
confusion over plain or volatile memory effects it is recommended that
the method weakCompareAndSetPlain(boolean, boolean)
be used instead.newValue
if the current value == expectedValue
,
with memory effects as specified by VarHandle.weakCompareAndSetPlain(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulweakCompareAndSetPlain(boolean, boolean)
public boolean weakCompareAndSetPlain(boolean expectedValue, boolean newValue)
newValue
if the current value == expectedValue
,
with memory effects as specified by VarHandle.weakCompareAndSetPlain(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulpublic final void set(boolean newValue)
newValue
,
with memory effects as specified by VarHandle.setVolatile(java.lang.Object...)
.newValue
- the new valuepublic final void lazySet(boolean newValue)
newValue
,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...)
.newValue
- the new valuepublic final boolean getAndSet(boolean newValue)
newValue
and returns the old value,
with memory effects as specified by VarHandle.getAndSet(java.lang.Object...)
.newValue
- the new valuepublic String toString()
public final boolean getPlain()
volatile
.public final void setPlain(boolean newValue)
newValue
, with memory semantics
of setting as if the variable was declared non-volatile
and non-final
.newValue
- the new valuepublic final boolean getOpaque()
VarHandle.getOpaque(java.lang.Object...)
.public final void setOpaque(boolean newValue)
newValue
,
with memory effects as specified by VarHandle.setOpaque(java.lang.Object...)
.newValue
- the new valuepublic final boolean getAcquire()
VarHandle.getAcquire(java.lang.Object...)
.public final void setRelease(boolean newValue)
newValue
,
with memory effects as specified by VarHandle.setRelease(java.lang.Object...)
.newValue
- the new valuepublic final boolean compareAndExchange(boolean expectedValue, boolean newValue)
newValue
if the current value,
referred to as the witness value, == expectedValue
,
with memory effects as specified by
VarHandle.compareAndExchange(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuepublic final boolean compareAndExchangeAcquire(boolean expectedValue, boolean newValue)
newValue
if the current value,
referred to as the witness value, == expectedValue
,
with memory effects as specified by
VarHandle.compareAndExchangeAcquire(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuepublic final boolean compareAndExchangeRelease(boolean expectedValue, boolean newValue)
newValue
if the current value,
referred to as the witness value, == expectedValue
,
with memory effects as specified by
VarHandle.compareAndExchangeRelease(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuepublic final boolean weakCompareAndSetVolatile(boolean expectedValue, boolean newValue)
newValue
if the current
value == expectedValue
,
with memory effects as specified by
VarHandle.weakCompareAndSet(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulpublic final boolean weakCompareAndSetAcquire(boolean expectedValue, boolean newValue)
newValue
if the current
value == expectedValue
,
with memory effects as specified by
VarHandle.weakCompareAndSetAcquire(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successfulpublic final boolean weakCompareAndSetRelease(boolean expectedValue, boolean newValue)
newValue
if the current
value == expectedValue
,
with memory effects as specified by
VarHandle.weakCompareAndSetRelease(java.lang.Object...)
.expectedValue
- the expected valuenewValue
- the new valuetrue
if successful Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-internal+0-adhoc.mlchung.jdk9-jdeps