- java.lang.Object
-
- java.util.concurrent.atomic.AtomicIntegerArray
-
- All Implemented Interfaces:
-
Serializable
public class AtomicIntegerArray extends Object implements Serializable
其中元素可以原子更新的int数组。 有关原子访问属性的说明,请参阅VarHandle规范。- 从以下版本开始:
- 1.5
- 另请参见:
- Serialized Form
-
-
构造方法摘要
构造方法 Constructor 描述 AtomicIntegerArray(int length)创建给定长度的新AtomicIntegerArray,所有元素最初为零。AtomicIntegerArray(int[] array)创建一个新的AtomicIntegerArray,其长度与从给定数组复制的所有元素相同。
-
方法摘要
所有方法 接口方法 具体的方法 弃用的方法 Modifier and Type 方法 描述 intaccumulateAndGet(int i, int x, IntBinaryOperator accumulatorFunction)将索引号为i的元素原子更新(由VarHandle.compareAndSet(java.lang.Object...)指定的内存效果),并将给定函数应用于当前值和给定值,返回更新后的值。intaddAndGet(int i, int delta)原子地将给定值添加到索引号为i的元素,具有由VarHandle.getAndAdd(java.lang.Object...)指定的内存效果。intcompareAndExchange(int i, int expectedValue, int newValue)如果元素的当前值(称为 见证值== expectedValue)具有由VarHandle.compareAndExchange(java.lang.Object...)指定的记忆效应,== expectedValue索引i为newValue的元素原子设置为 newValue 。intcompareAndExchangeAcquire(int i, int expectedValue, int newValue)如果元素的当前值,被称为 见证值== expectedValue,具有由VarHandle.compareAndExchangeAcquire(java.lang.Object...)指定的记忆效应,== expectedValue索引i为newValue的元素原子设置为 newValue 。intcompareAndExchangeRelease(int i, int expectedValue, int newValue)如果元素的当前值(称为见 值== expectedValue)具有由VarHandle.compareAndExchangeRelease(java.lang.Object...)指定的记忆效应,则原子将索引i为newValue的元素设置为 newValue 。booleancompareAndSet(int i, int expectedValue, int newValue)如果元素的当前值== expectedValue具有VarHandle.compareAndSet(java.lang.Object...)指定的记忆效应,则将索引i为newValue的元素原子设置为 newValue 。intdecrementAndGet(int i)按索引i原子地递减元素的值,其值由VarHandle.getAndAdd(java.lang.Object...)指定。intget(int i)返回索引号为i的元素的当前值,由VarHandle.getVolatile(java.lang.Object...)指定的内存效果。intgetAcquire(int i)返回索引号为i的元素的当前值,具有VarHandle.getAcquire(java.lang.Object...)指定的内存效果。intgetAndAccumulate(int i, int x, IntBinaryOperator accumulatorFunction)原始更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的内存效果)索引号为i的元素,并将给定函数应用于当前值和给定值,返回上一个值。intgetAndAdd(int i, int delta)原子地将给定的值添加到索引号为i的元素,具有由VarHandle.getAndAdd(java.lang.Object...)指定的内存效果。intgetAndDecrement(int i)原子递减元件的索引值i如通过指定,记忆效应VarHandle.getAndAdd(java.lang.Object...)。intgetAndIncrement(int i)按索引i原子地增加元素的值,具有由VarHandle.getAndAdd(java.lang.Object...)指定的内存效果。intgetAndSet(int i, int newValue)intgetAndUpdate(int i, IntUnaryOperator updateFunction)原子更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的内存效果)索引号为i的元素与应用给定函数的结果,返回上一个值。intgetOpaque(int i)返回索引号为i的元素的当前值,由VarHandle.getOpaque(java.lang.Object...)指定的内存效果。intgetPlain(int i)返回索引号为i的元素的当前值,其读取的内存语义就好像变量被声明为非volatile。intincrementAndGet(int i)在索引i原子方式增加元素的值,其值由VarHandle.getAndAdd(java.lang.Object...)指定。voidlazySet(int i, int newValue)intlength()返回数组的长度。voidset(int i, int newValue)voidsetOpaque(int i, int newValue)voidsetPlain(int i, int newValue)将索引i为newValue的元素设置为newValue,其内存语义设置为该变量被声明为非volatile,final。voidsetRelease(int i, int newValue)StringtoString()返回数组的当前值的String表示形式。intupdateAndGet(int i, IntUnaryOperator updateFunction)原子更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的内存效果)索引号为i的元素与应用给定函数的结果,返回更新的值。booleanweakCompareAndSet(int i, int expectedValue, int newValue)已过时。该方法具有明显的记忆效应,但方法名称表示易失性记忆效应(参见方法如compareAndExchange(int, int, int)和compareAndSet(int, int, int))。 为了避免在简单或易失性记忆效应上的混淆,建议使用方法weakCompareAndSetPlain(int, int, int)。booleanweakCompareAndSetAcquire(int i, int expectedValue, int newValue)如果元素的当前值为== expectedValue,具有由VarHandle.weakCompareAndSetAcquire(java.lang.Object...)指定的记忆效应,则可以将索引i为newValue的元素原子设置为 newValue 。booleanweakCompareAndSetPlain(int i, int expectedValue, int newValue)如果元素的当前值为== expectedValue,具有由VarHandle.weakCompareAndSetPlain(java.lang.Object...)指定的记忆效应,则可以将索引i为newValue的元素原子设置为 newValue 。booleanweakCompareAndSetRelease(int i, int expectedValue, int newValue)可能以原子方式设置在索引元件i到newValue如果该元素的当前值== expectedValue如通过指定,记忆效应VarHandle.weakCompareAndSetRelease(java.lang.Object...)。booleanweakCompareAndSetVolatile(int i, int expectedValue, int newValue)如果元素的当前值为== expectedValue,具有由VarHandle.weakCompareAndSet(java.lang.Object...)指定的记忆效应,则可以将索引i为newValue的元素原子设置为 newValue 。
-
-
-
构造方法详细信息
-
AtomicIntegerArray
public AtomicIntegerArray(int length)
创建给定长度的新AtomicIntegerArray,所有元素最初为零。- 参数
-
length- 数组的长度
-
AtomicIntegerArray
public AtomicIntegerArray(int[] array)
创建一个新的AtomicIntegerArray,其长度与从给定数组复制的所有元素相同。- 参数
-
array- 从中复制元素的数组 - 异常
-
NullPointerException- 如果数组为空
-
-
方法详细信息
-
length
public final int length()
返回数组的长度。- 结果
- 数组的长度
-
get
public final int get(int i)
返回索引号为i的元素的当前值,由VarHandle.getVolatile(java.lang.Object...)指定的内存效果。- 参数
-
i- 索引 - 结果
- 当前值
-
set
public final void set(int i, int newValue)- 参数
-
i- 指数 -
newValue- 新值
-
lazySet
public final void lazySet(int i, int newValue)- 参数
-
i- 索引 -
newValue- 新值 - 从以下版本开始:
- 1.6
-
getAndSet
public final int getAndSet(int i, int newValue)- 参数
-
i- 指数 -
newValue- 新值 - 结果
- 以前的值
-
compareAndSet
public final boolean compareAndSet(int i, int expectedValue, int newValue)- 参数
-
i- 指数 -
expectedValue- 预期值 -
newValue- 新值 - 结果
-
true如果成功。 False return表示实际值不等于预期值。
-
weakCompareAndSet
@Deprecated(since="9") public final boolean weakCompareAndSet(int i, int expectedValue, int newValue)
已过时。 该方法具有简单的记忆效应,但方法名称表示易失性记忆效应(参见方法如compareAndExchange(int, int, int)和compareAndSet(int, int, int))。 为了避免在简单或易失性记忆效应上的混淆,建议使用方法weakCompareAndSetPlain(int, int, int)。如果元素的当前值为== expectedValue,具有由VarHandle.weakCompareAndSetPlain(java.lang.Object...)指定的记忆效应,则可以将索引i为newValue的元素原子设置为 newValue 。- 参数
-
i- 索引 -
expectedValue- 预期值 -
newValue- 新价值 - 结果
-
true如果成功 - 另请参见:
-
weakCompareAndSetPlain(int, int, int)
-
weakCompareAndSetPlain
public final boolean weakCompareAndSetPlain(int i, int expectedValue, int newValue)如果元素的当前值为== expectedValue,具有由VarHandle.weakCompareAndSetPlain(java.lang.Object...)指定的记忆效应,则可以将索引i为newValue的元素原子设置为 newValue 。- 参数
-
i- 索引 -
expectedValue- 期望值 -
newValue- 新值 - 结果
-
true如果成功 - 从以下版本开始:
- 9
-
getAndIncrement
public final int getAndIncrement(int i)
原子递增元件的索引值i如通过指定,记忆效应VarHandle.getAndAdd(java.lang.Object...)。相当于
getAndAdd(i, 1)。- 参数
-
i- 索引 - 结果
- 以前的值
-
getAndDecrement
public final int getAndDecrement(int i)
原子递减元件的索引值i如通过指定,记忆效应VarHandle.getAndAdd(java.lang.Object...)。相当于
getAndAdd(i, -1)。- 参数
-
i- 索引 - 结果
- 以前的值
-
getAndAdd
public final int getAndAdd(int i, int delta)原子地将给定的值添加到索引号为i的元素,具有由VarHandle.getAndAdd(java.lang.Object...)指定的内存效果。- 参数
-
i- 索引 -
delta- 要添加的值 - 结果
- 以前的值
-
incrementAndGet
public final int incrementAndGet(int i)
原子递增元件的索引值i如通过指定,记忆效应VarHandle.getAndAdd(java.lang.Object...)。相当于
addAndGet(i, 1)。- 参数
-
i- 指数 - 结果
- 更新的值
-
decrementAndGet
public final int decrementAndGet(int i)
原子地递减索引号为i的元素的值,具有由VarHandle.getAndAdd(java.lang.Object...)指定的记忆效应。相当于
addAndGet(i, -1)。- 参数
-
i- 索引 - 结果
- 更新的值
-
addAndGet
public final int addAndGet(int i, int delta)原子地将给定的值添加到索引号为i的元素,具有由VarHandle.getAndAdd(java.lang.Object...)指定的记忆效应。- 参数
-
i- 索引 -
delta- 要添加的值 - 结果
- 更新的值
-
getAndUpdate
public final int getAndUpdate(int i, IntUnaryOperator updateFunction)原子更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的内存效果)索引号为i的元素与应用给定函数的结果,返回上一个值。 该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。- 参数
-
i- 索引 -
updateFunction- 一个无副作用的功能 - 结果
- 以前的值
- 从以下版本开始:
- 1.8
-
updateAndGet
public final int updateAndGet(int i, IntUnaryOperator updateFunction)使用索引i的元素与应用给定函数的结果进行原子更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的内存效果),返回更新的值。 该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。- 参数
-
i- 索引 -
updateFunction- 无副作用的功能 - 结果
- 更新的值
- 从以下版本开始:
- 1.8
-
getAndAccumulate
public final int getAndAccumulate(int i, int x, IntBinaryOperator accumulatorFunction)原始更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的内存效果)索引号为i的元素,并将给定的函数应用于当前值和给定值,返回上一个值。 该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。 该函数以索引i作为其第一个参数的元素的当前值应用,给定的更新作为第二个参数。- 参数
-
i- 索引 -
x- 更新值 -
accumulatorFunction- 两个参数的无效副作用 - 结果
- 以前的值
- 从以下版本开始:
- 1.8
-
accumulateAndGet
public final int accumulateAndGet(int i, int x, IntBinaryOperator accumulatorFunction)原子更新(具有VarHandle.compareAndSet(java.lang.Object...)指定的内存效果)索引号为i的元素,并将给定函数应用于当前值和给定值,返回更新后的值。 该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。 该函数应用索引i作为第一个参数的元素的当前值,给定更新作为第二个参数。- 参数
-
i- 索引 -
x- 更新值 -
accumulatorFunction- 两个参数的无效副作用 - 结果
- 更新的值
- 从以下版本开始:
- 1.8
-
getPlain
public final int getPlain(int i)
返回索引号为i的元素的当前值,读取的内存语义就好像变量被声明为非volatile。- 参数
-
i- 索引 - 结果
- 价值
- 从以下版本开始:
- 9
-
setPlain
public final void setPlain(int i, int newValue)将索引i为newValue的元素设置为newValue,其内存语义设置为该变量被声明为非volatilefinal。- 参数
-
i- 索引 -
newValue- 新的价值 - 从以下版本开始:
- 9
-
getOpaque
public final int getOpaque(int i)
返回索引号为i的元素的当前值,由VarHandle.getOpaque(java.lang.Object...)指定的内存效果。- 参数
-
i- 索引 - 结果
- 价值
- 从以下版本开始:
- 9
-
setOpaque
public final void setOpaque(int i, int newValue)- 参数
-
i- 索引 -
newValue- 新值 - 从以下版本开始:
- 9
-
getAcquire
public final int getAcquire(int i)
返回索引号为i的元素的当前值,具有VarHandle.getAcquire(java.lang.Object...)指定的内存效果。- 参数
-
i- 索引 - 结果
- 价值
- 从以下版本开始:
- 9
-
setRelease
public final void setRelease(int i, int newValue)- 参数
-
i- 索引 -
newValue- 新价值 - 从以下版本开始:
- 9
-
compareAndExchange
public final int compareAndExchange(int i, int expectedValue, int newValue)如果元素的当前值(称为 见证值== expectedValue)具有由VarHandle.compareAndExchange(java.lang.Object...)指定的记忆效应,== expectedValue索引i为newValue的元素原子设置为 newValue 。- 参数
-
i- 索引 -
expectedValue- 预期值 -
newValue- 新值 - 结果
- 见证价值,如果成功,将与预期价值相同
- 从以下版本开始:
- 9
-
compareAndExchangeAcquire
public final int compareAndExchangeAcquire(int i, int expectedValue, int newValue)以原子方式设置在索引元件i到newValue如果该元素的当前值,被称为 证人值 ,== expectedValue如通过指定,记忆效应VarHandle.compareAndExchangeAcquire(java.lang.Object...)。- 参数
-
i- 索引 -
expectedValue- 预期值 -
newValue- 新值 - 结果
- 见证价值,如果成功,将与预期价值相同
- 从以下版本开始:
- 9
-
compareAndExchangeRelease
public final int compareAndExchangeRelease(int i, int expectedValue, int newValue)如果元素的当前值(称为 见证值== expectedValue)具有由VarHandle.compareAndExchangeRelease(java.lang.Object...)指定的记忆效应,== expectedValue索引i为newValue的元素原子设置为 newValue 。- 参数
-
i- 索引 -
expectedValue- 预期值 -
newValue- 新价值 - 结果
- 见证价值,如果成功,将与预期价值相同
- 从以下版本开始:
- 9
-
weakCompareAndSetVolatile
public final boolean weakCompareAndSetVolatile(int i, int expectedValue, int newValue)如果元素的当前值为== expectedValue,具有由VarHandle.weakCompareAndSet(java.lang.Object...)指定的记忆效应,则可以将索引i为newValue的元素原子地设置为 newValue 。- 参数
-
i- 索引 -
expectedValue- 预期值 -
newValue- 新值 - 结果
-
true如果成功 - 从以下版本开始:
- 9
-
weakCompareAndSetAcquire
public final boolean weakCompareAndSetAcquire(int i, int expectedValue, int newValue)可能以原子方式设置在索引元件i到newValue如果该元素的当前值== expectedValue如通过指定,记忆效应VarHandle.weakCompareAndSetAcquire(java.lang.Object...)。- 参数
-
i- 索引 -
expectedValue- 期望值 -
newValue- 新值 - 结果
-
true如果成功 - 从以下版本开始:
- 9
-
weakCompareAndSetRelease
public final boolean weakCompareAndSetRelease(int i, int expectedValue, int newValue)可能以原子方式设置在索引元件i到newValue如果该元素的当前值== expectedValue如通过指定,记忆效应VarHandle.weakCompareAndSetRelease(java.lang.Object...)。- 参数
-
i- 索引 -
expectedValue- 预期值 -
newValue- 新值 - 结果
-
true如果成功 - 从以下版本开始:
- 9
-
-