本文整理汇总了Java中java.util.concurrent.atomic.DoubleAccumulator.get方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleAccumulator.get方法的具体用法?Java DoubleAccumulator.get怎么用?Java DoubleAccumulator.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.DoubleAccumulator
的用法示例。
在下文中一共展示了DoubleAccumulator.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAccumulateAndGetMT
import java.util.concurrent.atomic.DoubleAccumulator; //导入方法依赖的package包/类
/**
* accumulates by multiple threads produce correct result
*/
public void testAccumulateAndGetMT() {
final int incs = 1000000;
final int nthreads = 4;
final ExecutorService pool = Executors.newCachedThreadPool();
DoubleAccumulator a = new DoubleAccumulator(Double::max, 0.0);
Phaser phaser = new Phaser(nthreads + 1);
for (int i = 0; i < nthreads; ++i)
pool.execute(new AccTask(a, phaser, incs));
phaser.arriveAndAwaitAdvance();
phaser.arriveAndAwaitAdvance();
double expected = incs - 1;
double result = a.get();
assertEquals(expected, result);
pool.shutdown();
}
示例2: testDoubleAccumulator
import java.util.concurrent.atomic.DoubleAccumulator; //导入方法依赖的package包/类
static void testDoubleAccumulator() {
DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
a.accumulate(17.5d);
DoubleAccumulator result = echo(a);
if (result.get() != a.get())
throw new RuntimeException("Unexpected value");
a.reset();
result.reset();
if (result.get() != a.get())
throw new RuntimeException("Unexpected value after reset");
checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
示例3: run
import java.util.concurrent.atomic.DoubleAccumulator; //导入方法依赖的package包/类
public void run() {
phaser.arriveAndAwaitAdvance();
DoubleAccumulator a = acc;
for (int i = 0; i < incs; ++i)
a.accumulate(i);
result = a.get();
phaser.arrive();
}