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