本文整理匯總了Java中java.util.concurrent.atomic.LongAdder.add方法的典型用法代碼示例。如果您正苦於以下問題:Java LongAdder.add方法的具體用法?Java LongAdder.add怎麽用?Java LongAdder.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.atomic.LongAdder
的用法示例。
在下文中一共展示了LongAdder.add方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: IntConsumer
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
@Test
public void IntConsumer()
{
LongAdder adder = new LongAdder();
// TODO - Convert the anonymous inner class to a lambda
IntConsumer consumer = new IntConsumer()
{
@Override
public void accept(int value)
{
adder.add((long)value);
}
};
IntStream.rangeClosed(1, 5).forEach(consumer);
Assert.assertEquals(15, adder.longValue());
}
示例2: LongConsumer
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
@Test
public void LongConsumer()
{
LongAdder adder = new LongAdder();
// TODO - Convert the anonymous inner class to a lambda
LongConsumer consumer = new LongConsumer()
{
@Override
public void accept(long value)
{
adder.add(value);
}
};
LongStream.rangeClosed(1, 5).forEach(consumer);
Assert.assertEquals(15, adder.longValue());
}
示例3: test_long_add
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
public void test_long_add() throws Exception {
LongAdder adder = new LongAdder();
adder.add(3);
String json = JSON.toJSONString(adder);
assertEquals("{\"value\":3}", json);
}
示例4: testLongadder
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
@Test
public void testLongadder(){
LongAdder adder = new LongAdder();
adder.add(1);
adder.add(2);
// fixme
System.out.println(adder.longValue());
}
示例5: testLongAdder
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
static void testLongAdder() {
LongAdder a = new LongAdder();
a.add(45);
LongAdder result = echo(a);
if (result.longValue() != a.longValue())
throw new RuntimeException("Unexpected longValue");
checkSerialClassName(a, "java.util.concurrent.atomic.LongAdder$SerializationProxy");
}
示例6: testAddAndSum
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
/**
* add adds given value to current, and sum returns current value
*/
public void testAddAndSum() {
LongAdder ai = new LongAdder();
ai.add(2);
assertEquals(2, ai.sum());
ai.add(-4);
assertEquals(-2, ai.sum());
}
示例7: testReset
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
/**
* reset() causes subsequent sum() to return zero
*/
public void testReset() {
LongAdder ai = new LongAdder();
ai.add(2);
assertEquals(2, ai.sum());
ai.reset();
assertEquals(0, ai.sum());
}
示例8: testSumThenReset
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
/**
* sumThenReset() returns sum; subsequent sum() returns zero
*/
public void testSumThenReset() {
LongAdder ai = new LongAdder();
ai.add(2);
assertEquals(2, ai.sum());
assertEquals(2, ai.sumThenReset());
assertEquals(0, ai.sum());
}
示例9: testSerialization
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
/**
* a deserialized/reserialized adder holds same value
*/
public void testSerialization() throws Exception {
LongAdder x = new LongAdder();
LongAdder y = serialClone(x);
assertNotSame(x, y);
x.add(-22);
LongAdder z = serialClone(x);
assertNotSame(y, z);
assertEquals(-22, x.sum());
assertEquals(0, y.sum());
assertEquals(-22, z.sum());
}
示例10: 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); }
}
示例11: set
import java.util.concurrent.atomic.LongAdder; //導入方法依賴的package包/類
/**
* Sets the value of a metric for a given type and key.
*
* @param type
* the type
* @param key
* the key
* @param value
* the value
*/
public void set(String type, String key, long value) {
LongAdder adder = new LongAdder();
adder.add(value);
values.computeIfAbsent(type, t -> new ConcurrentHashMap<>()).put(key, adder);
}