Most visited

Recently visited

Added in API level 1

AtomicBoolean

public class AtomicBoolean
extends Object implements Serializable

java.lang.Object
    java.util.concurrent.atomic.AtomicBoolean


可以自动更新的boolean值。 有关原子变量属性的说明,请参阅java.util.concurrent.atomic包规范。 AtomicBoolean用于原子更新标志等应用程序,不能用作Boolean的替代品。

摘要(Summary)

Public constructors

AtomicBoolean(boolean initialValue)

用给定的初始值创建一个新的 AtomicBoolean

AtomicBoolean()

创建一个新的 AtomicBoolean ,初始值为 false

公共方法(Public methods)

final boolean compareAndSet(boolean expect, boolean update)

如果当前值为 ==原子值将该值设置为给定的更新值。

final boolean get()

返回当前值。

final boolean getAndSet(boolean newValue)

原子级设置为给定值并返回以前的值。

final void lazySet(boolean newValue)

最终设置为给定值。

final void set(boolean newValue)

无条件设置为给定值。

String toString()

返回当前值的字符串表示形式。

boolean weakCompareAndSet(boolean expect, boolean update)

如果当前值 ==为预期值, ==原子值将该值设置为给定的更新值。

继承方法(Inherited methods)

From class java.lang.Object

Public constructors

AtomicBoolean

Added in API level 1
AtomicBoolean (boolean initialValue)

用给定的初始值创建一个新的 AtomicBoolean

参数(Parameters)
initialValue boolean: the initial value

AtomicBoolean

Added in API level 1
AtomicBoolean ()

创建一个新的 AtomicBoolean ,初始值为 false

公共方法(Public methods)

compareAndSet

Added in API level 1
boolean compareAndSet (boolean expect, 
                boolean update)

如果当前值 ==为预期值, ==原子值将该值设置为给定的更新值。

参数(Parameters)
expect boolean: the expected value
update boolean: the new value
返回(Returns)
boolean true if successful. False return indicates that the actual value was not equal to the expected value.

get

Added in API level 1
boolean get ()

返回当前值。

返回(Returns)
boolean the current value

getAndSet

Added in API level 1
boolean getAndSet (boolean newValue)

原子级设置为给定值并返回以前的值。

参数(Parameters)
newValue boolean: the new value
返回(Returns)
boolean the previous value

lazySet

Added in API level 9
void lazySet (boolean newValue)

最终设置为给定值。

参数(Parameters)
newValue boolean: the new value

set

Added in API level 1
void set (boolean newValue)

无条件设置为给定值。

参数(Parameters)
newValue boolean: the new value

toString

Added in API level 1
String toString ()

返回当前值的字符串表示形式。

返回(Returns)
String the String representation of the current value

weakCompareAndSet

Added in API level 1
boolean weakCompareAndSet (boolean expect, 
                boolean update)

如果当前值 ==为期望值, ==原子值将该值设置为给定的更新值。

May fail spuriously and does not provide ordering guarantees ,所以只有很少的 compareAndSet合适的选择。

参数(Parameters)
expect boolean: the expected value
update boolean: the new value
返回(Returns)
boolean true if successful

Hooray!