JavaTM 2 Platform
Standard Ed. 6

java.util.concurrent.atomic
類別 AtomicIntegerArray

java.lang.Object
  繼承者 java.util.concurrent.atomic.AtomicIntegerArray
所有已實作的介面:
Serializable

public class AtomicIntegerArray
extends Object
implements Serializable

可以用原子方式更新其元素的 int 陣列。有關原子變數屬性的描述,請參閱 java.util.concurrent.atomic 套件規範。

從以下版本開始:
1.5
另請參見:
序列化表格

建構子摘要
AtomicIntegerArray(int length)
          創建給定長度的新 AtomicIntegerArray。
AtomicIntegerArray(int[] array)
          創建與給定陣列具有相同長度的新 AtomicIntegerArray,並從給定陣列複製其所有元素。
 
方法摘要
 int addAndGet(int i, int delta)
          以原子方式將給定值與索引 i 的元素相加。
 boolean compareAndSet(int i, int expect, int update)
          如果當前值 == 預期值,則以原子方式將位置 i 的元素設置為給定的更新值。
 int decrementAndGet(int i)
          以原子方式將索引 i 的元素減 1。
 int get(int i)
          獲取位置 i 的當前值。
 int getAndAdd(int i, int delta)
          以原子方式將給定值與索引 i 的元素相加。
 int getAndDecrement(int i)
          以原子方式將索引 i 的元素減 1。
 int getAndIncrement(int i)
          以原子方式將索引 i 的元素加 1。
 int getAndSet(int i, int newValue)
          將位置 i 的元素以原子方式設置為給定值,並返回舊值。
 int incrementAndGet(int i)
          以原子方式將索引 i 的元素加 1。
 void lazySet(int i, int newValue)
          最後將位置 i 的元素設置為給定值。
 int length()
          返回該陣列的長度。
 void set(int i, int newValue)
          將位置 i 的元素設置為給定值。
 String toString()
          返回陣列當前值的字元串表示形式。
 boolean weakCompareAndSet(int i, int expect, int update)
          如果當前值 == 預期值,則以原子方式將位置 i 的元素設置為給定的更新值。
 
從類別 java.lang.Object 繼承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

建構子詳細資訊

AtomicIntegerArray

public AtomicIntegerArray(int length)
創建給定長度的新 AtomicIntegerArray。

參數:
length - 該陣列的長度

AtomicIntegerArray

public AtomicIntegerArray(int[] array)
創建與給定陣列具有相同長度的新 AtomicIntegerArray,並從給定陣列複製其所有元素。

參數:
array - 從中複製元素的陣列
拋出:
NullPointerException - 如果陣列為 null
方法詳細資訊

length

public final int length()
返回該陣列的長度。

返回:
該陣列的長度

get

public final int get(int i)
獲取位置 i 的當前值。

參數:
i - 索引
返回:
當前值

set

public final void set(int i,
                      int newValue)
將位置 i 的元素設置為給定值。

參數:
i - 索引
newValue - 新值

lazySet

public final void lazySet(int i,
                          int newValue)
最後將位置 i 的元素設置為給定值。

參數:
i - 索引
newValue - 新值
從以下版本開始:
1.6

getAndSet

public final int getAndSet(int i,
                           int newValue)
將位置 i 的元素以原子方式設置為給定值,並返回舊值。

參數:
i - 索引
newValue - 新值
返回:
以前的值

compareAndSet

public final boolean compareAndSet(int i,
                                   int expect,
                                   int update)
如果當前值 == 預期值,則以原子方式將位置 i 的元素設置為給定的更新值。

參數:
i - 索引
expect - 預期值
update - 新值
返回:
如果成功,則返回 true。返回 false 指示實際值與預期值不相等。

weakCompareAndSet

public final boolean weakCompareAndSet(int i,
                                       int expect,
                                       int update)
如果當前值 == 預期值,則以原子方式將位置 i 的元素設置為給定的更新值。

可能意外失敗並且不提供排序保證,所以只是在很少的情況下才對 compareAndSet 進行適當地選擇。

參數:
i - 索引
expect - 預期值
update - 新值
返回:
如果成功,則返回 true。

getAndIncrement

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

參數:
i - 索引
返回:
以前的值

getAndDecrement

public final int getAndDecrement(int i)
以原子方式將索引 i 的元素減 1。

參數:
i - 索引
返回:
以前的值

getAndAdd

public final int getAndAdd(int i,
                           int delta)
以原子方式將給定值與索引 i 的元素相加。

參數:
i - 索引
delta - 要加上的值
返回:
以前的值

incrementAndGet

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

參數:
i - 索引
返回:
更新的值

decrementAndGet

public final int decrementAndGet(int i)
以原子方式將索引 i 的元素減 1。

參數:
i - 索引
返回:
更新的值

addAndGet

public final int addAndGet(int i,
                           int delta)
以原子方式將給定值與索引 i 的元素相加。

參數:
i - 索引
delta - 要加上的值
返回:
更新的值

toString

public String toString()
返回陣列當前值的字元串表示形式。

覆寫:
類別 Object 中的 toString
返回:
陣列當前值的字元串表示形式。

JavaTM 2 Platform
Standard Ed. 6

提交錯誤或意見

版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only