public class AtomicInteger extends Number implements Serializable
int可能原子更新的值。
有关原子变量属性的描述,请参阅java.util.concurrent.atomic包规范。
一个AtomicInteger用于诸如原子增量计数器的应用程序中,不能用作Integer的替代品 。
但是,这个类确实扩展了Number以允许通过处理基于数字类的工具和实用程序的统一访问。
| Constructor and Description |
|---|
AtomicInteger()
创建一个新的AtomicInteger,初始值为
0 。
|
AtomicInteger(int initialValue)
用给定的初始值创建一个新的AtomicInteger。
|
| Modifier and Type | Method and Description |
|---|---|
int |
accumulateAndGet(int x, IntBinaryOperator accumulatorFunction)
使用将给定函数应用于当前值和给定值的结果原子更新当前值,返回更新后的值。
|
int |
addAndGet(int delta)
将给定的值原子地添加到当前值。
|
boolean |
compareAndSet(int expect, int update)
如果当前值
==为预期值,则将该值原子设置为给定的更新值。
|
int |
decrementAndGet()
原子减1当前值。
|
double |
doubleValue()
返回此值
AtomicInteger为
double一个宽元转换后。
|
float |
floatValue()
返回此值
AtomicInteger为
float一个宽元转换后。
|
int |
get()
获取当前值。
|
int |
getAndAccumulate(int x, IntBinaryOperator accumulatorFunction)
使用给定函数应用给当前值和给定值的结果原子更新当前值,返回上一个值。
|
int |
getAndAdd(int delta)
将给定的值原子地添加到当前值。
|
int |
getAndDecrement()
原子减1当前值。
|
int |
getAndIncrement()
原子上增加一个当前值。
|
int |
getAndSet(int newValue)
将原子设置为给定值并返回旧值。
|
int |
getAndUpdate(IntUnaryOperator updateFunction)
用应用给定函数的结果原子更新当前值,返回上一个值。
|
int |
incrementAndGet()
原子上增加一个当前值。
|
int |
intValue()
将
AtomicInteger的值作为
int 。
|
void |
lazySet(int newValue)
最终设定为给定值。
|
long |
longValue()
返回此值
AtomicInteger为
long一个宽元转换后。
|
void |
set(int newValue)
设置为给定值。
|
String |
toString()
返回当前值的String表示形式。
|
int |
updateAndGet(IntUnaryOperator updateFunction)
使用给定函数的结果原子更新当前值,返回更新的值。
|
boolean |
weakCompareAndSet(int expect, int update)
如果当前值
==为预期值,则将值设置为给定更新值。
|
byteValue, shortValuepublic AtomicInteger(int initialValue)
initialValue - 初始值
public AtomicInteger()
0 。
public final int get()
public final void set(int newValue)
newValue - 新值
public final void lazySet(int newValue)
newValue - 新值
public final int getAndSet(int newValue)
newValue - 新值
public final boolean compareAndSet(int expect,
int update)
==为预期值,则将该值原子设置为给定的更新值。
expect - 预期值
update - 新价值
true如果成功。
False return表示实际值不等于预期值。
public final boolean weakCompareAndSet(int expect,
int update)
==的预期值,则将该值原子设置为给定的更新值。
May fail spuriously and does not provide ordering guarantees ,所以很少适合替代compareAndSet 。
expect - 预期值
update - 新的价值
true如果成功
public final int getAndIncrement()
public final int getAndDecrement()
public final int getAndAdd(int delta)
delta - 要添加的值
public final int incrementAndGet()
public final int decrementAndGet()
public final int addAndGet(int delta)
delta - 要添加的值
public final int getAndUpdate(IntUnaryOperator updateFunction)
updateFunction - 无副作用的功能
public final int updateAndGet(IntUnaryOperator updateFunction)
updateFunction - 无副作用的功能
public final int getAndAccumulate(int x,
IntBinaryOperator accumulatorFunction)
x - 更新值
accumulatorFunction - 两个参数的无效副作用
public final int accumulateAndGet(int x,
IntBinaryOperator accumulatorFunction)
x - 更新值
accumulatorFunction - 两个参数的无副作用的函数
public int intValue()
AtomicInteger的值作为
int 。
public long longValue()
AtomicInteger为
long一个宽元转换后。
public float floatValue()
AtomicInteger为
float一个宽元转换后。
floatValue在类别
Number
float之后表示的
float 。
public double doubleValue()
AtomicInteger为
double一个宽元转换后。
doubleValue在类别
Number
double之后表示的
double 。
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.