public class AtomicIntegerArray
extends Object implements Serializable
| java.lang.Object | |
| ↳ | java.util.concurrent.atomic.AtomicIntegerArray |
一个int数组,其中元素可以自动更新。 有关原子变量属性的描述,请参阅java.util.concurrent.atomic包规范。
Public constructors |
|
|---|---|
AtomicIntegerArray(int length) 创建给定长度的新AtomicIntegerArray,所有元素初始为零。 |
|
AtomicIntegerArray(int[] array) 创建一个新的AtomicIntegerArray,其长度与从给定数组中复制的所有元素相同。 |
|
Public methods |
|
|---|---|
final int |
accumulateAndGet(int i, int x, IntBinaryOperator accumulatorFunction) 使用将给定函数应用于当前值和给定值的结果,以索引 |
final int |
addAndGet(int i, int delta) 将指定值以原子方式添加到索引为 |
final boolean |
compareAndSet(int i, int expect, int update) 如果当前值为 |
final int |
decrementAndGet(int i) 在 |
final int |
get(int i) 获取位置 |
final int |
getAndAccumulate(int i, int x, IntBinaryOperator accumulatorFunction) 使用将给定函数应用于当前值和给定值的结果,以索引 |
final int |
getAndAdd(int i, int delta) 将给定值以原子方式添加到索引为 |
final int |
getAndDecrement(int i) 原子法将索引为 |
final int |
getAndIncrement(int i) 在索引 |
final int |
getAndSet(int i, int newValue) 以原子方式将位置 |
final int |
getAndUpdate(int i, IntUnaryOperator updateFunction) 使用给定函数的结果以索引 |
final int |
incrementAndGet(int i)
|
final void |
lazySet(int i, int newValue) 最终将位置 |
final int |
length() 返回数组的长度。 |
final void |
set(int i, int newValue) 将位置 |
String |
toString() 返回数组当前值的字符串表示形式。 |
final int |
updateAndGet(int i, IntUnaryOperator updateFunction) 使用给定函数的结果原子更新索引 |
final boolean |
weakCompareAndSet(int i, int expect, int update) 如果当前值为 |
Inherited methods |
|
|---|---|
java.lang.Object
|
|
AtomicIntegerArray (int length)
创建给定长度的新AtomicIntegerArray,所有元素初始为零。
| Parameters | |
|---|---|
length |
int: the length of the array |
AtomicIntegerArray (int[] array)
创建一个新的AtomicIntegerArray,其长度与从给定数组中复制的所有元素相同。
| Parameters | |
|---|---|
array |
int: the array to copy elements from |
| Throws | |
|---|---|
NullPointerException |
if array is null |
int accumulateAndGet (int i,
int x,
IntBinaryOperator accumulatorFunction)
使用将给定函数应用于当前值和给定值的结果,以索引i原子更新元素,返回更新的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。 该函数以索引i处的当前值作为其第一个参数,并将给定的更新作为第二个参数来应用。
| Parameters | |
|---|---|
i |
int: the index |
x |
int: the update value |
accumulatorFunction |
IntBinaryOperator: a side-effect-free function of two arguments |
| Returns | |
|---|---|
int |
the updated value |
int addAndGet (int i,
int delta)
将给定值以原子方式添加到索引为 i的元素。
| Parameters | |
|---|---|
i |
int: the index |
delta |
int: the value to add |
| Returns | |
|---|---|
int |
the updated value |
boolean compareAndSet (int i,
int expect,
int update)
如果当前值 ==为期望值, i原子方式将位置 i上的元素设置为给定的更新值。
| Parameters | |
|---|---|
i |
int: the index |
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 (int i)
原子减少一个索引为 i的元素。
| Parameters | |
|---|---|
i |
int: the index |
| Returns | |
|---|---|
int |
the updated value |
int get (int i)
获取位置 i的当前值。
| Parameters | |
|---|---|
i |
int: the index |
| Returns | |
|---|---|
int |
the current value |
int getAndAccumulate (int i,
int x,
IntBinaryOperator accumulatorFunction)
将指定函数应用于当前值和给定值的结果以i方式更新索引i处的元素,并返回以前的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。 该函数的索引为i ,当前值为第一个参数,给定的更新为第二个参数。
| Parameters | |
|---|---|
i |
int: the index |
x |
int: the update value |
accumulatorFunction |
IntBinaryOperator: a side-effect-free function of two arguments |
| Returns | |
|---|---|
int |
the previous value |
int getAndAdd (int i,
int delta)
将给定值以原子方式添加到索引 i处的元素。
| Parameters | |
|---|---|
i |
int: the index |
delta |
int: the value to add |
| Returns | |
|---|---|
int |
the previous value |
int getAndDecrement (int i)
在 i处减少一个元素。
| Parameters | |
|---|---|
i |
int: the index |
| Returns | |
|---|---|
int |
the previous value |
int getAndIncrement (int i)
i增加一个元素。
| Parameters | |
|---|---|
i |
int: the index |
| Returns | |
|---|---|
int |
the previous value |
int getAndSet (int i,
int newValue)
以原子方式将位置 i上的元素设置为给定值并返回旧值。
| Parameters | |
|---|---|
i |
int: the index |
newValue |
int: the new value |
| Returns | |
|---|---|
int |
the previous value |
int getAndUpdate (int i,
IntUnaryOperator updateFunction)
使用给定函数的结果原子更新索引i处的元素,并返回以前的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。
| Parameters | |
|---|---|
i |
int: the index |
updateFunction |
IntUnaryOperator: a side-effect-free function |
| Returns | |
|---|---|
int |
the previous value |
int incrementAndGet (int i)
i增加一个元素。
| Parameters | |
|---|---|
i |
int: the index |
| Returns | |
|---|---|
int |
the updated value |
void lazySet (int i,
int newValue)
最终将位置 i处的元素设置为给定值。
| Parameters | |
|---|---|
i |
int: the index |
newValue |
int: the new value |
void set (int i,
int newValue)
将位置 i上的元素设置为给定值。
| Parameters | |
|---|---|
i |
int: the index |
newValue |
int: the new value |
String toString ()
返回数组当前值的字符串表示形式。
| Returns | |
|---|---|
String |
the String representation of the current values of array |
int updateAndGet (int i,
IntUnaryOperator updateFunction)
使用给定函数的结果原子更新索引i处的元素,并返回更新后的值。 该函数应该是无副作用的,因为当尝试更新由于线程之间的争用而失败时,它可能会被重新应用。
| Parameters | |
|---|---|
i |
int: the index |
updateFunction |
IntUnaryOperator: a side-effect-free function |
| Returns | |
|---|---|
int |
the updated value |
boolean weakCompareAndSet (int i,
int expect,
int update)
如果当前值 ==为期望值, ==位置 i处的元素设置为给定的更新值。
May fail spuriously and does not provide ordering guarantees ,所以只有很少的 compareAndSet替代选择。
| Parameters | |
|---|---|
i |
int: the index |
expect |
int: the expected value |
update |
int: the new value |
| Returns | |
|---|---|
boolean |
true if successful |