本文整理匯總了Java中java.util.concurrent.atomic.AtomicIntegerArray.get方法的典型用法代碼示例。如果您正苦於以下問題:Java AtomicIntegerArray.get方法的具體用法?Java AtomicIntegerArray.get怎麽用?Java AtomicIntegerArray.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.atomic.AtomicIntegerArray
的用法示例。
在下文中一共展示了AtomicIntegerArray.get方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import java.util.concurrent.atomic.AtomicIntegerArray; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
SerializeWriter out = serializer.getWriter();
if (object != null) {
AtomicIntegerArray array = (AtomicIntegerArray) object;
int len = array.length();
out.append('[');
for (int i = 0; i < len; i++) {
int val = array.get(i);
if (i != 0) {
out.write(',');
}
out.writeInt(val);
}
out.append(']');
} else if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
out.write("[]");
} else {
out.writeNull();
}
}
示例2: write
import java.util.concurrent.atomic.AtomicIntegerArray; //導入方法依賴的package包/類
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
SerializeWriter out = serializer.getWriter();
if (object == null) {
if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
out.write("[]");
} else {
out.writeNull();
}
return;
}
AtomicIntegerArray array = (AtomicIntegerArray) object;
int len = array.length();
out.append('[');
for (int i = 0; i < len; ++i) {
int val = array.get(i);
if (i != 0) {
out.write(',');
}
out.writeInt(val);
}
out.append(']');
}
示例3: getWorkStatus
import java.util.concurrent.atomic.AtomicIntegerArray; //導入方法依賴的package包/類
private int getWorkStatus(int groupId, int deviceId) {
AtomicIntegerArray array = WORK_STATUS_STORAGE.get(groupId);
return array.get(deviceId);
}
示例4: main
import java.util.concurrent.atomic.AtomicIntegerArray; //導入方法依賴的package包/類
/**
* @param args
*/
public static void main(String[] args) {
final int THREADS=100;
/**
* Atomic array whose elements will be incremented and decremented
*/
AtomicIntegerArray vector=new AtomicIntegerArray(1000);
/*
* An incrementer task
*/
Incrementer incrementer=new Incrementer(vector);
/*
* A decrementer task
*/
Decrementer decrementer=new Decrementer(vector);
/*
* Create and execute 100 incrementer and 100 decrementer tasks
*/
Thread threadIncrementer[]=new Thread[THREADS];
Thread threadDecrementer[]=new Thread[THREADS];
for (int i=0; i<THREADS; i++) {
threadIncrementer[i]=new Thread(incrementer);
threadDecrementer[i]=new Thread(decrementer);
threadIncrementer[i].start();
threadDecrementer[i].start();
}
/*
* Wait for the finalization of all the tasks
*/
for (int i=0; i<THREADS; i++) {
try {
threadIncrementer[i].join();
threadDecrementer[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/*
* Write the elements different from 0
*/
int errors=0;
for (int i=0; i<vector.length(); i++) {
if (vector.get(i)!=0) {
System.out.println("Vector["+i+"] : "+vector.get(i));
errors++;
}
}
if (errors==0) {
System.out.printf("No errors found\n");
}
System.out.println("Main: End of the example");
}
示例5: getChargeStatus
import java.util.concurrent.atomic.AtomicIntegerArray; //導入方法依賴的package包/類
/**
* 從服務器暫存庫中,獲取設備狀態
*
* @param groupId 設備組號
* @param deviceId 設備號
* @return 指定設備的狀態
*/
private int getChargeStatus(int groupId, int deviceId) {
AtomicIntegerArray array = CHARGE_STATUS_STORAGE.get(groupId);
return array.get(deviceId);
}