Java 类java.util.concurrent.atomic.DoubleAccumulator 实例源码

项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * 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();
}
项目:AddGun    文件:ShotTracker.java   
public void run() {
    DoubleAccumulator offset = new DoubleAccumulator((a,b) -> {return a + b;}, 0.0);

    shotQueue.removeIf(s -> {
        offset.accumulate(s.decay());
        return s.ticksLeft == 0;
    });

    this.offset = offset;

    if (shotQueue.isEmpty()) {
        throw new RuntimeException("All done for now for this player");
    }
}
项目:jdk8u-jdk    文件:Serial.java   
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");
}
项目:openjdk-jdk10    文件:Serial.java   
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");
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * new instance initialized to supplied identity
 */
public void testConstructor() {
    for (double identity : new double[] {
             Double.NEGATIVE_INFINITY,
             Double.POSITIVE_INFINITY,
             Double.MIN_VALUE,
             Double.MAX_VALUE,
             0.0,
         })
        assertEquals(identity,
                     new DoubleAccumulator(Double::max, identity).get());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * accumulate accumulates given value to current, and get returns current value
 */
public void testAccumulateAndGet() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    acc.accumulate(2.0);
    assertEquals(2.0, acc.get());
    acc.accumulate(-4.0);
    assertEquals(2.0, acc.get());
    acc.accumulate(4.0);
    assertEquals(4.0, acc.get());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * reset() causes subsequent get() to return zero
 */
public void testReset() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    acc.accumulate(2.0);
    assertEquals(2.0, acc.get());
    acc.reset();
    assertEquals(0.0, acc.get());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * getThenReset() returns current value; subsequent get() returns zero
 */
public void testGetThenReset() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    acc.accumulate(2.0);
    assertEquals(2.0, acc.get());
    assertEquals(2.0, acc.getThenReset());
    assertEquals(0.0, acc.get());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * toString returns current value.
 */
public void testToString() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    assertEquals("0.0", acc.toString());
    acc.accumulate(1.0);
    assertEquals(Double.toString(1.0), acc.toString());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0, acc.intValue());
    acc.accumulate(1.0);
    assertEquals(1, acc.intValue());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * longValue returns current value.
 */
public void testLongValue() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0, acc.longValue());
    acc.accumulate(1.0);
    assertEquals(1, acc.longValue());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * floatValue returns current value.
 */
public void testFloatValue() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0.0f, acc.floatValue());
    acc.accumulate(1.0);
    assertEquals(1.0f, acc.floatValue());
}
项目:openjdk-jdk10    文件:DoubleAccumulatorTest.java   
/**
 * doubleValue returns current value.
 */
public void testDoubleValue() {
    DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0.0, acc.doubleValue());
    acc.accumulate(1.0);
    assertEquals(1.0, acc.doubleValue());
}
项目:openjdk9    文件:Serial.java   
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");
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * accumulate accumulates given value to current, and get returns current value
 */
public void testAccumulateAndGet() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    ai.accumulate(-4.0);
    assertEquals(2.0, ai.get());
    ai.accumulate(4.0);
    assertEquals(4.0, ai.get());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * reset() causes subsequent get() to return zero
 */
public void testReset() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    ai.reset();
    assertEquals(0.0, ai.get());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * getThenReset() returns current value; subsequent get() returns zero
 */
public void testGetThenReset() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    ai.accumulate(2.0);
    assertEquals(2.0, ai.get());
    assertEquals(2.0, ai.getThenReset());
    assertEquals(0.0, ai.get());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * toString returns current value.
 */
public void testToString() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals("0.0", ai.toString());
    ai.accumulate(1.0);
    assertEquals(Double.toString(1.0), ai.toString());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0, ai.intValue());
    ai.accumulate(1.0);
    assertEquals(1, ai.intValue());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * longValue returns current value.
 */
public void testLongValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0, ai.longValue());
    ai.accumulate(1.0);
    assertEquals(1, ai.longValue());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * floatValue returns current value.
 */
public void testFloatValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0.0f, ai.floatValue());
    ai.accumulate(1.0);
    assertEquals(1.0f, ai.floatValue());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * doubleValue returns current value.
 */
public void testDoubleValue() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0.0, ai.doubleValue());
    ai.accumulate(1.0);
    assertEquals(1.0, ai.doubleValue());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
public void run() {
    phaser.arriveAndAwaitAdvance();
    DoubleAccumulator a = acc;
    for (int i = 0; i < incs; ++i)
        a.accumulate(i);
    result = a.get();
    phaser.arrive();
}
项目:jdk8u_jdk    文件:Serial.java   
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");
}
项目:lookaside_java-1.8.0-openjdk    文件:Serial.java   
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");
}
项目:ocpj8-samples    文件:JavaConcurrencyExample.java   
/**
 * Use synchronized keyword and java.util.concurrent.atomic package to
 * control the order of thread execution
 */
synchronized private void synchronizedExample() {
    number = number + number;

    // Atomic
    AtomicInteger i = new AtomicInteger();
    i.incrementAndGet();
    i.getAndIncrement();

    i.decrementAndGet();
    i.getAndDecrement();

    i.getAndAdd(10);
    i.addAndGet(10);

    i.updateAndGet(v -> v * 2);

    i = new AtomicInteger(10);
    i.accumulateAndGet(10, (a, b) -> a * b);
    System.out.print("AtomicInteger : ");
    System.out.println(i);

    AtomicBoolean ab;
    AtomicInteger ai;
    DoubleAdder da;
    LongAdder la;
    DoubleAccumulator dac;
    LongAccumulator lac;
}
项目:infobip-open-jdk-8    文件:Serial.java   
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");
}
项目:jdk8u-dev-jdk    文件:Serial.java   
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");
}
项目:OLD-OpenJDK8    文件:Serial.java   
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");
}
项目:Java-9-Concurrency-Cookbook-Second-Edition    文件:Account.java   
public Account() {
    balance = new AtomicLong();
    operations = new LongAdder();
    commission = new DoubleAccumulator((x,y)-> x+y*0.2, 0);
}
项目:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming    文件:Account.java   
public Account() {
    balance = new AtomicLong();
    operations = new LongAdder();
    commission = new DoubleAccumulator((x,y)-> x+y*0.2, 0);
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
/**
 * default constructed initializes to zero
 */
public void testConstructor() {
    DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
    assertEquals(0.0, ai.get());
}
项目:openjdk9    文件:DoubleAccumulatorTest.java   
AccTask(DoubleAccumulator acc, Phaser phaser, int incs) {
    this.acc = acc;
    this.phaser = phaser;
    this.incs = incs;
}