A {@code boolean} value that may be updated atomically. See the
package specification for
description of the properties of atomic variables. An
{@code AtomicBoolean} is used in applications such as atomically
updated flags, and cannot be used as a replacement for a
.
Method from java.util.concurrent.atomic.AtomicBoolean Detail: |
public final boolean compareAndSet(boolean expect,
boolean update) {
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
}
Atomically sets the value to the given updated value
if the current value {@code ==} the expected value. |
public final boolean get() {
return value != 0;
}
Returns the current value. |
public final boolean getAndSet(boolean newValue) {
for (;;) {
boolean current = get();
if (compareAndSet(current, newValue))
return current;
}
}
Atomically sets to the given value and returns the previous value. |
public final void lazySet(boolean newValue) {
int v = newValue ? 1 : 0;
unsafe.putOrderedInt(this, valueOffset, v);
}
Eventually sets to the given value. |
public final void set(boolean newValue) {
value = newValue ? 1 : 0;
}
Unconditionally sets to the given value. |
public String toString() {
return Boolean.toString(get());
}
Returns the String representation of the current value. |
public boolean weakCompareAndSet(boolean expect,
boolean update) {
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
}
Atomically sets the value to the given updated value
if the current value {@code ==} the expected value.
May fail spuriously
and does not provide ordering guarantees, so is only rarely an
appropriate alternative to {@code compareAndSet}. |