类java.util.concurrent.atomic.DoubleAdder源码实例Demo

下面列出了怎么用java.util.concurrent.atomic.DoubleAdder的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: j2objc   文件: DoubleAdderTest.java
/**
 * 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();
    DoubleAdder a = new DoubleAdder();
    CyclicBarrier barrier = new CyclicBarrier(nthreads + 1);
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, barrier, incs));
    barrier.await();
    barrier.await();
    double total = (long)nthreads * incs;
    double sum = a.sum();
    assertEquals(sum, total);
    pool.shutdown();
}
 
源代码2 项目: dragonwell8_jdk   文件: DoubleAdderDemo.java
static void adderTest(int nthreads, int incs) {
    System.out.print("DoubleAdder  ");
    Phaser phaser = new Phaser(nthreads + 1);
    DoubleAdder a = new DoubleAdder();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.sum());
}
 
源代码3 项目: dragonwell8_jdk   文件: DoubleAdderDemo.java
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
源代码4 项目: dragonwell8_jdk   文件: Serial.java
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
源代码5 项目: TencentKona-8   文件: DoubleAdderDemo.java
static void adderTest(int nthreads, int incs) {
    System.out.print("DoubleAdder  ");
    Phaser phaser = new Phaser(nthreads + 1);
    DoubleAdder a = new DoubleAdder();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.sum());
}
 
源代码6 项目: TencentKona-8   文件: DoubleAdderDemo.java
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
源代码7 项目: TencentKona-8   文件: Serial.java
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
源代码8 项目: j2objc   文件: DoubleAdderTest.java
/**
 * reset() causes subsequent sum() to return zero
 */
public void testReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    ai.reset();
    assertEquals(0.0, ai.sum());
}
 
源代码9 项目: native-obfuscator   文件: DoubleAdderDemo.java
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
源代码10 项目: native-obfuscator   文件: Serial.java
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
源代码11 项目: jdk8u60   文件: DoubleAdderDemo.java
static void adderTest(int nthreads, int incs) {
    System.out.print("DoubleAdder  ");
    Phaser phaser = new Phaser(nthreads + 1);
    DoubleAdder a = new DoubleAdder();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.sum());
}
 
源代码12 项目: jdk8u60   文件: DoubleAdderDemo.java
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
源代码13 项目: jdk8u60   文件: Serial.java
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
源代码14 项目: coroutines   文件: ForkJoinExample.java
/***************************************
 * Main.
 *
 * @param rArgs
 */
public static void main(String[] rArgs)
{
	ThreadLocalRandom rRandom	    = ThreadLocalRandom.current();
	long[]			  aCoefficients = new long[TASK_SIZE];

	for (int i = 0; i < TASK_SIZE; i++)
	{
		aCoefficients[i] = rRandom.nextLong(0, 1024 * 1024);
	}

	Profiler aProfiler =
		new Profiler(ForkJoinExample.class.getSimpleName());

	ScopeFuture<DoubleAdder> aResult =
		produce(
			RESULT,
			scope -> computeOrSplit(scope, aCoefficients, 0, TASK_SIZE));

	System.out.printf("Sum: %f\n", aResult.get().sum());

	aProfiler.measure(
		String.format(
			"%d tasks\nwith a batch size of %d",
			TASK_SIZE,
			BATCH_SIZE));
	aProfiler.printSummary();
}
 
源代码15 项目: openjdk-jdk8u   文件: DoubleAdderDemo.java
static void adderTest(int nthreads, int incs) {
    System.out.print("DoubleAdder  ");
    Phaser phaser = new Phaser(nthreads + 1);
    DoubleAdder a = new DoubleAdder();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.sum());
}
 
源代码16 项目: openjdk-jdk8u   文件: DoubleAdderDemo.java
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
源代码17 项目: openjdk-jdk8u   文件: Serial.java
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
public FixedBoundaryVictoriaMetricsHistogram() {
    this.zeros = new AtomicLong(0);
    this.lower = new AtomicLong(0);
    this.upper = new AtomicLong(0);
    this.sum = new DoubleAdder();

    this.values = new AtomicReferenceArray<>(BUCKETS_COUNT);
}
 
源代码19 项目: micrometer   文件: CumulativeDistributionSummary.java
public CumulativeDistributionSummary(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig,
                                     double scale, boolean supportsAggregablePercentiles) {
    super(id, clock, distributionStatisticConfig, scale, supportsAggregablePercentiles);
    this.count = new AtomicLong();
    this.total = new DoubleAdder();
    this.max = new TimeWindowMax(clock, distributionStatisticConfig);
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: DoubleAdderDemo.java
static void adderTest(int nthreads, int incs) {
    System.out.print("DoubleAdder  ");
    Phaser phaser = new Phaser(nthreads + 1);
    DoubleAdder a = new DoubleAdder();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.sum());
}
 
源代码21 项目: j2objc   文件: DoubleAdderTest.java
/**
 * floatValue returns current value.
 */
public void testFloatValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0.0f, ai.floatValue());
    ai.add(1.0);
    assertEquals(1.0f, ai.floatValue());
}
 
源代码22 项目: openjdk-jdk8u-backup   文件: DoubleAdderDemo.java
public void run() {
    phaser.arriveAndAwaitAdvance();
    phaser.arriveAndAwaitAdvance();
    DoubleAdder a = adder;
    for (int i = 0; i < incs; ++i)
        a.add(1.0);
    result = a.sum();
    phaser.arrive();
}
 
源代码23 项目: j2objc   文件: DoubleAdderTest.java
public void run() {
    try {
        barrier.await();
        DoubleAdder a = adder;
        for (int i = 0; i < incs; ++i)
            a.add(1.0);
        result = a.sum();
        barrier.await();
    } catch (Throwable t) { throw new Error(t); }
}
 
源代码24 项目: openjdk-jdk9   文件: DoubleAdderDemo.java
static void adderTest(int nthreads, int incs) {
    System.out.print("DoubleAdder  ");
    Phaser phaser = new Phaser(nthreads + 1);
    DoubleAdder a = new DoubleAdder();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new AdderTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.sum());
}
 
源代码25 项目: j2objc   文件: DoubleAdderTest.java
/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(0, ai.intValue());
    ai.add(1.0);
    assertEquals(1, ai.intValue());
}
 
源代码26 项目: openjdk-jdk9   文件: Serial.java
static void testDoubleAdder() {
    DoubleAdder a = new DoubleAdder();
    a.add(20.1d);
    DoubleAdder result = echo(a);
    if (result.doubleValue() != a.doubleValue())
        throw new RuntimeException("Unexpected doubleValue");

    checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
 
源代码27 项目: openjdk-jdk9   文件: DoubleAdderTest.java
/**
 * reset() causes subsequent sum() to return zero
 */
public void testReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    ai.reset();
    assertEquals(0.0, ai.sum());
}
 
源代码28 项目: openjdk-jdk9   文件: DoubleAdderTest.java
/**
 * sumThenReset() returns sum; subsequent sum() returns zero
 */
public void testSumThenReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    assertEquals(2.0, ai.sumThenReset());
    assertEquals(0.0, ai.sum());
}
 
源代码29 项目: j2objc   文件: DoubleAdderTest.java
/**
 * sumThenReset() returns sum; subsequent sum() returns zero
 */
public void testSumThenReset() {
    DoubleAdder ai = new DoubleAdder();
    ai.add(2.0);
    assertEquals(2.0, ai.sum());
    assertEquals(2.0, ai.sumThenReset());
    assertEquals(0.0, ai.sum());
}
 
源代码30 项目: openjdk-jdk9   文件: DoubleAdderTest.java
/**
 * toString returns current value.
 */
public void testToString() {
    DoubleAdder ai = new DoubleAdder();
    assertEquals(Double.toString(0.0), ai.toString());
    ai.add(1.0);
    assertEquals(Double.toString(1.0), ai.toString());
}