public class AtomicBoolean extends Object implements Serializable
boolean值可以用原子更新。
有关原子变量属性的描述,请参阅java.util.concurrent.atomic包规范。
一个AtomicBoolean用于诸如原子更新标志的应用程序,不能用作替代Boolean 。
| Constructor and Description |
|---|
AtomicBoolean()
创建一个新的
AtomicBoolean ,初始值为
false 。
|
AtomicBoolean(boolean initialValue)
用给定的初始值创建一个新的
AtomicBoolean 。
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
compareAndSet(boolean expect, boolean update)
如果当前值为
==的预期值,则将该值原子设置为给定的更新值。
|
boolean |
get()
返回当前值。
|
boolean |
getAndSet(boolean newValue)
将原子设置为给定值并返回上一个值。
|
void |
lazySet(boolean newValue)
最终设定为给定值。
|
void |
set(boolean newValue)
无条件地设置为给定的值。
|
String |
toString()
返回当前值的String表示形式。
|
boolean |
weakCompareAndSet(boolean expect, boolean update)
如果当前值为
==为预期值,则将该值原子设置为给定的更新值。
|
public AtomicBoolean(boolean initialValue)
AtomicBoolean 。
initialValue - 初始值
public AtomicBoolean()
AtomicBoolean ,初始值为
false 。
public final boolean get()
public final boolean compareAndSet(boolean expect,
boolean update)
==的预期值,则将该值原子设置为给定的更新值。
expect - 期望值
update - 新值
true如果成功。
False return表示实际值不等于预期值。
public boolean weakCompareAndSet(boolean expect,
boolean update)
==为预期值,则将该值原子设置为给定的更新值。
May fail spuriously and does not provide ordering guarantees ,所以只是很少适合替代compareAndSet 。
expect - 预期值
update - 新的价值
true如果成功
public final void set(boolean newValue)
newValue - 新的价值
public final void lazySet(boolean newValue)
newValue - 新的价值
public final boolean getAndSet(boolean newValue)
newValue - 新值
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, 2014, Oracle and/or its affiliates. All rights reserved.