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()
原子由一个电流值递减。
|
double |
doubleValue()
为扩大基本转换后的
double返回该
AtomicInteger价值。
|
float |
floatValue()
为扩大基本转换后的
float返回该
AtomicInteger价值。
|
int |
get()
获取当前值。
|
int |
getAndAccumulate(int x, IntBinaryOperator accumulatorFunction)
自动更新当前值与给定的功能应用到当前和给定值的结果,返回前一个值。
|
int |
getAndAdd(int delta)
自动添加给定值和当前值。
|
int |
getAndDecrement()
原子由一个电流值递减。
|
int |
getAndIncrement()
原子逐个增加电流值。
|
int |
getAndSet(int newValue)
自动设置为给定的值并返回旧值。
|
int |
getAndUpdate(IntUnaryOperator updateFunction)
自动更新当前值与结果应用给定的函数,返回前一个值。
|
int |
incrementAndGet()
原子逐个增加电流值。
|
int |
intValue()
作为一个
int返回该
AtomicInteger价值。
|
void |
lazySet(int newValue)
最终设置为给定的值。
|
long |
longValue()
为扩大基本转换后的
long返回该
AtomicInteger价值。
|
void |
set(int newValue)
给定值的集合。
|
String |
toString()
返回当前值的字符串表示形式。
|
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如果成功。错误返回表示实际值不等于期望值。
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()
int返回该
AtomicInteger价值。
public long longValue()
long返回该
AtomicInteger价值。
public float floatValue()
float返回该
AtomicInteger价值。
floatValue 方法重写,继承类
Number
float后。
public double doubleValue()
double返回该
AtomicInteger价值。
doubleValue 方法重写,继承类
Number
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.