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