當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicIntegerArray.length方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:AtomicIntegerArrayCodec.java

示例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(']');
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:25,代碼來源:AtomicIntegerArrayCodec.java

示例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));
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:6,代碼來源:IntegerStatsDeltaAggregator.java

示例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");
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Concurrency-Cookbook-Second-Edition,代碼行數:62,代碼來源:Main.java

示例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));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:6,代碼來源:TestNMClientAsync.java


注:本文中的java.util.concurrent.atomic.AtomicIntegerArray.length方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。