本文整理汇总了Java中java.util.concurrent.atomic.AtomicIntegerArray.length方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicIntegerArray.length方法的具体用法?Java AtomicIntegerArray.length怎么用?Java AtomicIntegerArray.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.AtomicIntegerArray
的用法示例。
在下文中一共展示了AtomicIntegerArray.length方法的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: initializeArray
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
private void initializeArray(AtomicIntegerArray arr) {
for (int i = 0; i < arr.length(); i++) {
arr.set(i, Integer.valueOf(0));
}
}
示例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: assertAtomicIntegerArray
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
private void assertAtomicIntegerArray(AtomicIntegerArray array) {
for (int i = 0; i < array.length(); ++i) {
Assert.assertEquals(1, array.get(i));
}
}