public class AtomicInteger
extends Number implements Serializable
| java.lang.Object | ||
| ↳ | java.lang.Number | |
| ↳ | java.util.concurrent.atomic.AtomicInteger | |
可以自动更新的int值。 有关原子变量属性的说明,请参阅java.util.concurrent.atomic包规范。 AtomicInteger用于原子增量计数器等应用程序,不能用作Integer的替代品。 但是,该类确实扩展了Number以允许使用基于数字的类的工具和实用程序进行统一访问。
Public constructors |
|
|---|---|
AtomicInteger(int initialValue) 用给定的初始值创建一个新的AtomicInteger。 |
|
AtomicInteger() 创建一个初始值为 |
|
Public methods |
|
|---|---|
final int |
accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) 将给定函数应用于当前值和给定值的结果以原子方式更新当前值,并返回更新后的值。 |
final int |
addAndGet(int delta) 原子上将给定值添加到当前值。 |
final boolean |
compareAndSet(int expect, int update) 如果当前值 |
final int |
decrementAndGet() 原子减少一个当前值。 |
double |
doubleValue() 返回此值 |
float |
floatValue() 返回此值 |
final int |
get() 获取当前值。 |
final int |
getAndAccumulate(int x, IntBinaryOperator accumulatorFunction) 将给定函数应用于当前值和给定值的结果以原始方式更新当前值,并返回以前的值。 |
final int |
getAndAdd(int delta) 原子上将给定值添加到当前值。 |
final int |
getAndDecrement() 原子减少一个当前值。 |
final int |
getAndIncrement() 原子上增加一个当前值。 |
final int |
getAndSet(int newValue) 原子级设置为给定值并返回旧值。 |
final int |
getAndUpdate(IntUnaryOperator updateFunction) 用应用给定函数的结果原子地更新当前值,返回以前的值。 |
final int |
incrementAndGet() 原子上增加一个当前值。 |
int |
intValue() 返回此值 |
final void |
lazySet(int newValue) 最终设置为给定值。 |
long |
longValue() 返回此值 |
final void |
set(int newValue) 设置为给定值。 |
String |
toString() 返回当前值的字符串表示形式。 |
final int |
updateAndGet(IntUnaryOperator updateFunction) 使用给定函数的结果原子地更新当前值,并返回更新的值。 |
final boolean |
weakCompareAndSet(int expect, int update) 如果当前值 |
Inherited methods |
|
|---|---|
java.lang.Number
|
|
java.lang.Object
|
|
AtomicInteger (int initialValue)
用给定的初始值创建一个新的AtomicInteger。
| Parameters | |
|---|---|
initialValue |
int: the initial value |
int accumulateAndGet (int x,
IntBinaryOperator accumulatorFunction)
将给定函数应用于当前值和给定值的结果以原子方式更新当前值,并返回更新后的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。 该函数以当前值作为第一个参数,给定更新作为第二个参数应用。
| Parameters | |
|---|---|
x |
int: the update value |
accumulatorFunction |
IntBinaryOperator: a side-effect-free function of two arguments |
| Returns | |
|---|---|
int |
the updated value |
int addAndGet (int delta)
原子上将给定值添加到当前值。
| Parameters | |
|---|---|
delta |
int: the value to add |
| Returns | |
|---|---|
int |
the updated value |
boolean compareAndSet (int expect,
int update)
如果当前值 ==为预期值, ==原子级将该值设置为给定的更新值。
| Parameters | |
|---|---|
expect |
int: the expected value |
update |
int: the new value |
| Returns | |
|---|---|
boolean |
true if successful. False return indicates that the actual value was not equal to the expected value. |
int decrementAndGet ()
原子减少一个当前值。
| Returns | |
|---|---|
int |
the updated value |
double doubleValue ()
返回此值 AtomicInteger为 double一个宽元转换后。
| Returns | |
|---|---|
double |
the numeric value represented by this object after conversion to type double. |
float floatValue ()
返回此值 AtomicInteger为 float一个宽元转换后。
| Returns | |
|---|---|
float |
the numeric value represented by this object after conversion to type float. |
int getAndAccumulate (int x,
IntBinaryOperator accumulatorFunction)
将给定函数应用于当前值和给定值的结果以原始方式更新当前值,并返回以前的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。 该函数以当前值作为第一个参数,给定更新作为第二个参数应用。
| Parameters | |
|---|---|
x |
int: the update value |
accumulatorFunction |
IntBinaryOperator: a side-effect-free function of two arguments |
| Returns | |
|---|---|
int |
the previous value |
int getAndAdd (int delta)
原子上将给定值添加到当前值。
| Parameters | |
|---|---|
delta |
int: the value to add |
| Returns | |
|---|---|
int |
the previous value |
int getAndDecrement ()
原子减少一个当前值。
| Returns | |
|---|---|
int |
the previous value |
int getAndIncrement ()
原子上增加一个当前值。
| Returns | |
|---|---|
int |
the previous value |
int getAndSet (int newValue)
原子级设置为给定值并返回旧值。
| Parameters | |
|---|---|
newValue |
int: the new value |
| Returns | |
|---|---|
int |
the previous value |
int getAndUpdate (IntUnaryOperator updateFunction)
用应用给定函数的结果原子地更新当前值,返回以前的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。
| Parameters | |
|---|---|
updateFunction |
IntUnaryOperator: a side-effect-free function |
| Returns | |
|---|---|
int |
the previous value |
int incrementAndGet ()
原子上增加一个当前值。
| Returns | |
|---|---|
int |
the updated value |
int intValue ()
返回此值AtomicInteger为int 。 相当于get() 。
| Returns | |
|---|---|
int |
the numeric value represented by this object after conversion to type int. |
void lazySet (int newValue)
最终设置为给定值。
| Parameters | |
|---|---|
newValue |
int: the new value |
long longValue ()
返回此值 AtomicInteger为 long一个宽元转换后。
| Returns | |
|---|---|
long |
the numeric value represented by this object after conversion to type long. |
String toString ()
返回当前值的字符串表示形式。
| Returns | |
|---|---|
String |
the String representation of the current value |
int updateAndGet (IntUnaryOperator updateFunction)
使用给定函数的结果原子地更新当前值,并返回更新的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。
| Parameters | |
|---|---|
updateFunction |
IntUnaryOperator: a side-effect-free function |
| Returns | |
|---|---|
int |
the updated value |
boolean weakCompareAndSet (int expect,
int update)
如果当前值 ==为预期值, ==原子值将该值设置为给定的更新值。
May fail spuriously and does not provide ordering guarantees ,所以只有很少的 compareAndSet替代选择。
| Parameters | |
|---|---|
expect |
int: the expected value |
update |
int: the new value |
| Returns | |
|---|---|
boolean |
true if successful |