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!