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()
返回当前值的字符串表示形式。
|
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
如果成功。错误返回表示实际值不等于期望值。
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.