目录搜索
文字
分享


JavaTM 2 Platform
Standard Ed. 6

java.util.concurrent.atomic
类 AtomicBoolean

1

2

java.lang.Object

  <img src="../../../../resources/inherit.gif" alt="继承者 "><b>java.util.concurrent.atomic.AtomicBoolean</b>

所有已实现的接口:
Serializable

1

public class <b>AtomicBoolean</b>

extends Object
implements Serializable

可以用原子方式更新的 boolean 值。有关原子变量属性的描述,请参阅 java.util.concurrent.atomic 包规范。AtomicBoolean 可用在应用程序中(如以原子方式更新的标志),但不能用于替换 Boolean

从以下版本开始:
1.5
另请参见:
序列化表格

构造方法摘要
AtomicBoolean()
          使用初始值 false 创建新的 AtomicBoolean
AtomicBoolean(boolean initialValue)
          使用给定的初始值创建新的 AtomicBoolean
 
方法摘要
 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)
          如果当前值 == 预期值,则以原子方式将该值设置为给定的更新值。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造方法详细信息

AtomicBoolean

1

public <b>AtomicBoolean</b>(boolean initialValue)

使用给定的初始值创建新的 AtomicBoolean

参数:
initialValue - 初始值

AtomicBoolean

1

public <b>AtomicBoolean</b>()

使用初始值 false 创建新的 AtomicBoolean

方法详细信息

get

1

public final boolean <b>get</b>()

返回当前值。

返回:
当前值

compareAndSet

1

2

public final boolean <b>compareAndSet</b>(boolean expect,

                                   boolean update)

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

参数:
expect - 预期值
update - 新值
返回:
如果成功,则返回 true。返回 False 指示实际值与预期值不相等。

weakCompareAndSet

1

2

public boolean <b>weakCompareAndSet</b>(boolean expect,

                                 boolean update)

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

可能意外失败并且不提供排序保证,因此几乎只是 compareAndSet 的适当替代方法。

参数:
expect - 预期值
update - 新值
返回:
如果成功,则返回 true。

set

1

public final void <b>set</b>(boolean newValue)

无条件地设置为给定值。

参数:
newValue - 新值

lazySet

1

public final void <b>lazySet</b>(boolean newValue)

最终设置为给定值。

参数:
newValue - 新值
从以下版本开始:
1.6

getAndSet

1

public final boolean <b>getAndSet</b>(boolean newValue)

以原子方式设置为给定值,并返回以前的值。

参数:
newValue - 新值
返回:
以前的值

toString

1

public String <b>toString</b>()

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

覆盖:
Object 中的 toString
返回:
当前值的字符串表示形式。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。

上一篇:atomic下一篇:AtomicInteger