本文整理匯總了Java中java.util.concurrent.atomic.LongAdder.sum方法的典型用法代碼示例。如果您正苦於以下問題:Java LongAdder.sum方法的具體用法?Java LongAdder.sum怎麽用?Java LongAdder.sum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.atomic.LongAdder
的用法示例。
在下文中一共展示了LongAdder.sum方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAddAndSumMT
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
/**
* adds by multiple threads produce correct sum
*/
public void testAddAndSumMT() throws Throwable {
final int incs = 1000000;
final int nthreads = 4;
final ExecutorService pool = Executors.newCachedThreadPool();
LongAdder a = new LongAdder();
CyclicBarrier barrier = new CyclicBarrier(nthreads + 1);
for (int i = 0; i < nthreads; ++i)
pool.execute(new AdderTask(a, barrier, incs));
barrier.await();
barrier.await();
long total = (long)nthreads * incs;
long sum = a.sum();
assertEquals(sum, total);
pool.shutdown();
}
示例2: tearDown
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
/**
* Cleanups queue and deallocate directBuffers manually
*/
@TearDown(Level.Iteration)
public void tearDown() {
LongAdder counter = new LongAdder();
// cleanup
meter.retain((meterId, timestamp, value) -> counter.increment());
// cheat cleanup to initial size
long cnt = counter.sum();
for (int i = 0; i < cnt / 4096; i++)
meter.retain((meterId, timestamp, value) -> counter.increment());
System.out.println("processed: " + counter.sum() + " measures");
}
示例3: run
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
public void run() {
phaser.arriveAndAwaitAdvance();
phaser.arriveAndAwaitAdvance();
LongAdder a = adder;
for (int i = 0; i < incs; ++i)
a.increment();
result = a.sum();
phaser.arrive();
}
示例4: run
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
public void run() {
try {
barrier.await();
LongAdder a = adder;
for (int i = 0; i < incs; ++i)
a.add(1L);
result = a.sum();
barrier.await();
} catch (Throwable t) { throw new Error(t); }
}