1.类 AtomicLongArray

  public class AtomicLongArray extends Object implements Serializable

  可以用原子方式更新其元素的 long 数组

2.构造函数详解

AtomicLongArray

public AtomicLongArray(int length)
创建给定长度的新 AtomicLongArray。

 

参数:
length - 该数组的长度

AtomicLongArray

public AtomicLongArray(long[] array)
创建与给定数组具有相同长度的新 AtomicLongArray,并从给定数组复制其所有元素。

 

参数:
array - 从中复制元素的数组
抛出:
NullPointerException - 如果数组为 null

3.方法详解

length

public final int length()
返回该数组的长度。

 

返回:
该数组的长度

get

public final long get(int i)
获取位置 i 的当前值。

 

参数:
i - 索引
返回:
当前值

set

public final void set(int i,
                      long newValue)
将位置 i 的元素设置为给定值。

 

参数:
i - 索引
newValue - 新值

lazySet

public final void lazySet(int i,
                          long newValue)
最终将位置 i 的元素设置为给定值。

 

参数:
i - 索引
newValue - 新值
从以下版本开始:
1.6

getAndSet

public final long getAndSet(int i,
                            long newValue)
以原子方式将位置 i 的元素设置为给定值,并返回旧值。

 

参数:
i - 索引
newValue - 新值
返回:
以前的值

compareAndSet

public final boolean compareAndSet(int i,
                                   long expect,
                                   long update)
如果当前值 == 预期值,则以原子方式将该值设置为给定的更新值。

 

参数:
i - 索引
expect - 预期值
update - 新值
返回:
如果成功,则返回 true。返回 false 指示实际值与预期值不相等。

weakCompareAndSet

public final boolean weakCompareAndSet(int i,
                                       long expect,
                                       long update)
如果当前值 == 预期值,则以原子方式将该值设置为给定的更新值。

可能意外失败并且不提供排序保证,所以只能在很少的情况下对 compareAndSet 进行适当地选择。

 

参数:
i - 索引
expect - 预期值
update - 新值
返回:
如果成功,则返回 true。

getAndIncrement

public final long getAndIncrement(int i)
以原子方式将索引 i 的元素加 1。

 

参数:
i - 索引
返回:
以前的值

getAndDecrement

public final long getAndDecrement(int i)
以原子方式将索引 i 的元素减 1。

 

参数:
i - 索引
返回:
以前的值

getAndAdd

public final long getAndAdd(int i,
                            long delta)
以原子方式将给定值与索引 i 的元素相加。

 

参数:
i - 索引
delta - 要加上的值
返回:
以前的值

incrementAndGet

public final long incrementAndGet(int i)
以原子方式将索引 i 的元素加1。

 

参数:
i - 索引
返回:
更新的值

decrementAndGet

public final long decrementAndGet(int i)
以原子方式将索引 i 的元素减1。

 

参数:
i - 索引
返回:
更新的值

addAndGet

public long addAndGet(int i,
                      long delta)
以原子方式将给定值添加到索引 i 的元素。

 

参数:
i - 索引
delta - 要添加的值
返回:
更新的值

toString

public String toString()
返回数组当前值的字符串表示形式。

 

覆盖:
Object 中的 toString
返回:
数组当前值的字符串表示形式。
posted on 2016-03-08 16:56  TonyLoveTT  阅读(470)  评论(0编辑  收藏  举报