public class AtomicLongArray extends Object implements Serializable
long数组,其中元素可以原子更新。
有关原子变量属性的描述,请参阅java.util.concurrent.atomic封装规范。
| Constructor and Description |
|---|
AtomicLongArray(int length)
创建给定长度的新AtomicLongArray,所有元素最初为零。
|
AtomicLongArray(long[] array)
创建一个与原始数组相同长度的新的AtomicLongArray,并复制所有元素。
|
| Modifier and Type | Method and Description |
|---|---|
long |
accumulateAndGet(int i, long x, LongBinaryOperator accumulatorFunction)
以索引
i原子更新元素,并将给定函数应用于当前值和给定值,返回更新后的值。
|
long |
addAndGet(int i, long delta)
原子地将索引
i的给定值添加到元素。
|
boolean |
compareAndSet(int i, long expect, long update)
如果当前值
==为预期值,则
i地将位置
i处的元素设置为给定的更新值。
|
long |
decrementAndGet(int i)
索引
i的元素原子
i 。
|
long |
get(int i)
获取位置
i的当前值。
|
long |
getAndAccumulate(int i, long x, LongBinaryOperator accumulatorFunction)
以索引
i原子更新元素,并将给定函数应用于当前值和给定值,返回上一个值。
|
long |
getAndAdd(int i, long delta)
原子地将给定的值添加到索引
i中的元素。
|
long |
getAndDecrement(int i)
索引
i的元素原子
i 。
|
long |
getAndIncrement(int i)
在索引
i原子上增加一个元素。
|
long |
getAndSet(int i, long newValue)
将位置
i的元素原子设置为给定值并返回旧值。
|
long |
getAndUpdate(int i, LongUnaryOperator updateFunction)
以索引
i原子更新应用给定函数的结果,返回上一个值。
|
long |
incrementAndGet(int i)
索引号为
i的元素原子地增加一个。
|
void |
lazySet(int i, long newValue)
最终将位置
i的元素设置为给定值。
|
int |
length()
返回数组的长度。
|
void |
set(int i, long newValue)
将位置
i处的元素设置为给定值。
|
String |
toString()
返回数组的当前值的String表示形式。
|
long |
updateAndGet(int i, LongUnaryOperator updateFunction)
用索引
i的元素原子更新应用给定函数的结果,返回更新后的值。
|
boolean |
weakCompareAndSet(int i, long expect, long update)
如果当前值
==为预期值,则
i地将位置
i处的元素设置为给定的更新值。
|
public AtomicLongArray(int length)
length - 数组的长度
public AtomicLongArray(long[] array)
array -
array复制元素的数组
NullPointerException - 如果数组为空
public final int length()
public final long get(int i)
i的当前值。
i - 指数
public final void set(int i,
long newValue)
i处的元素设置为给定值。
i - 指数
newValue - 新的价值
public final void lazySet(int i,
long newValue)
i的元素设置为给定值。
i - 指数
newValue - 新价值
public final long getAndSet(int i,
long newValue)
i处的元素原子设置为给定值并返回旧值。
i - 指数
newValue - 新价值
public final boolean compareAndSet(int i,
long expect,
long update)
==为预期值,则
i地将位置
i处的元素设置为给定的更新值。
i - 指数
expect - 预期值
update - 新价值
true如果成功。
False return表示实际值不等于预期值。
public final boolean weakCompareAndSet(int i,
long expect,
long update)
==为预期值,则i地将位置i处的元素设置为给定的更新值。
May fail spuriously and does not provide ordering guarantees ,所以只是很少适合替代compareAndSet 。
i - 指数
expect - 预期值
update - 新价值
true如果成功
public final long getAndIncrement(int i)
i 。
i - 指数
public final long getAndDecrement(int i)
i的元素原子减少一个。
i - 指数
public final long getAndAdd(int i,
long delta)
i的给定值添加到元素。
i - 索引
delta - 要添加的值
public final long incrementAndGet(int i)
i原子地增加一个元素。
i - 索引
public final long decrementAndGet(int i)
i的元素原子
i 。
i - 索引
public long addAndGet(int i,
long delta)
i 。
i - 指数
delta - 要添加的值
public final long getAndUpdate(int i,
LongUnaryOperator updateFunction)
i原子更新应用给定函数的结果,返回上一个值。
该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。
i - 指数
updateFunction - 无副作用的功能
public final long updateAndGet(int i,
LongUnaryOperator updateFunction)
i的元素进行原子更新,并应用给定的函数,返回更新的值。
该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。
i - 指数
updateFunction - 无副作用的功能
public final long getAndAccumulate(int i,
long x,
LongBinaryOperator accumulatorFunction)
i原子更新元素,并将给定函数应用于当前值和给定值,返回上一个值。
该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。
该函数应用索引i作为其第一个参数的当前值,给定更新作为第二个参数。
i - 索引
x - 更新值
accumulatorFunction - 两个参数的无效副作用
public final long accumulateAndGet(int i,
long x,
LongBinaryOperator accumulatorFunction)
i原子更新元素,并将给定函数应用于当前值和给定值,返回更新后的值。
该功能应该是无副作用的,因为尝试的更新由于线程之间的争用而失败时可能会被重新应用。
该函数应用索引i作为其第一个参数的当前值,给定更新作为第二个参数。
i - 指数
x - 更新值
accumulatorFunction - 两个参数的无效副作用
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.