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