當前位置: 首頁>>代碼示例>>Java>>正文


Java LongAdder類代碼示例

本文整理匯總了Java中java.util.concurrent.atomic.LongAdder的典型用法代碼示例。如果您正苦於以下問題:Java LongAdder類的具體用法?Java LongAdder怎麽用?Java LongAdder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LongAdder類屬於java.util.concurrent.atomic包,在下文中一共展示了LongAdder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testForEachSequentially

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * forEachSequentially traverses all mappings
 */
public void testForEachSequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:ConcurrentHashMap8Test.java

示例2: testForEachInParallel

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * forEachInParallel traverses all mappings
 */
public void testForEachInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEach(1L, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:ConcurrentHashMap8Test.java

示例3: purgeBundle

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * Purges a Bundle from the system.
 * @param bundleid - Bundle Identifier
 */
public static void purgeBundle(Long bundleid) {
    if (bundleid == null) {
        return;
    }
    Map.Entry<LongAdder,List<Transaction>> bundleInfo =  bundles.get(bundleid);
    if (bundleInfo == null) {
        return;
    }
    long ts = System.currentTimeMillis();
    for(Transaction t : bundleInfo.getValue()) {
        t.setStatusTs(OperationStatus.FAILED, ts);
        purgeOperation(t.getClientId().toString() + "/" + bundleid + "/" + t.getOpId().toString());
    }
    bundles.remove(bundleid);
}
 
開發者ID:opendaylight,項目名稱:fpc,代碼行數:20,代碼來源:Transaction.java

示例4: 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());
}
 
開發者ID:BNYMellon,項目名稱:CodeKatas,代碼行數:17,代碼來源:PrimitiveFunctionalInterfaceTest.java

示例5: test

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
@Test
public void test() {
	if(nodeCount > 1) {
		final long connCountSum = nodeFreq.values().stream().mapToLong(LongAdder::sum).sum();
		final long avgConnCountPerNode = connCountSum / nodeCount;
		for(final String nodeAddr: nodeFreq.keySet()) {
			assertTrue(nodeFreq.get(nodeAddr).sum() > 0);
			assertEquals(
				"Node count: " + nodeCount + ", node: \"" + nodeAddr
					+ "\", expected connection count: " + avgConnCountPerNode + ", actual: "
					+ nodeFreq.get(nodeAddr).sum(),
				avgConnCountPerNode, nodeFreq.get(nodeAddr).sum(), 1.5 * avgConnCountPerNode
			);
		}
	} else {
		assertTrue(true);
	}
}
 
開發者ID:akurilov,項目名稱:netty-connection-pool,代碼行數:19,代碼來源:BasicMultiNodeConnPoolTest.java

示例6: testReloadCalledPeriodically

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
@Test
public void testReloadCalledPeriodically() {
    LongAdder numOfReloadCalls = new LongAdder();
    PeriodicalReloadStrategy strategy = PeriodicalReloadStrategy.builder()
            .withInterval(Duration.ofMillis(50))
            .build();

    try {
        strategy.start(numOfReloadCalls::increment);

        await("Reload called more then once")
                .atMost(5, TimeUnit.SECONDS)
                .until(() -> numOfReloadCalls.longValue() > 1);
    } finally {
        strategy.stop();
    }
}
 
開發者ID:conf4j,項目名稱:conf4j,代碼行數:18,代碼來源:PeriodicalReloadStrategyTest.java

示例7: measureRecommendationTraversal

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
@Benchmark
@Warmup(iterations = 10)
@Measurement(iterations = 10)
@Fork(1)
@Threads(4)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
public List measureRecommendationTraversal() throws IOException {
    Set<String> itemsYouLike = db.getOutgoingRelationshipNodeIds("LIKES", "person" + rand.nextInt(personCount));
    Map<String, LongAdder> occurrences = new HashMap<>();
    for (String item : itemsYouLike) {
        for (String person : db.getIncomingRelationshipNodeIds("LIKES", item)) {
            Set<String> itemsYouMightLike = db.getOutgoingRelationshipNodeIds("LIKES", person);
            itemsYouMightLike.removeAll(itemsYouLike);
            for (String unlikeditem : itemsYouMightLike) {
                occurrences.computeIfAbsent(unlikeditem, (t) -> new LongAdder()).increment();
            }
        }
    }
    List<Map.Entry<String, LongAdder>> itemList = new ArrayList<>(occurrences.entrySet());
    Collections.sort(itemList, (a, b) -> ( b.getValue().intValue() - a.getValue().intValue() ));
    return itemList.subList(0, Math.min(itemList.size(), 10));
}
 
開發者ID:maxdemarzi,項目名稱:GuancialeDB,代碼行數:24,代碼來源:GuancialeDBRecommendationBenchmark.java

示例8: doRunTest

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
private void doRunTest(int serverInstances, int threadsPerServer, int invocationsPerClient, int clientThreads, int delayPerRequest, int clientMaxWait) throws Exception {
  when(testService.getString(any())).thenAnswer(createAnswer(delayPerRequest));

  int totalServerThreads = serverInstances * threadsPerServer;
  long targetTime = delayPerRequest * clientThreads * invocationsPerClient / serverInstances / threadsPerServer;

  System.out.println(String.format("Running %d server instances with %d threads (threadsPerServer=%d delayPerRequest=%d)", totalServerThreads, serverInstances, threadsPerServer, delayPerRequest));
  System.out.println(String.format("Executing %d clients with %d requests/client (total %d requests)", clientThreads, invocationsPerClient, clientThreads * invocationsPerClient));
  System.out.println(String.format("Target time %dms", targetTime));

  for (int i = 0; i < serverInstances; i++) {
    setupServer(threadsPerServer);
  }


  LongAdder timer = new LongAdder();
  try (TimerContext ignored = TimerContext.timerMillis(timer::add)) {
    runParallelClients(invocationsPerClient, clientThreads, clientMaxWait);
  }

  System.out.println(String.format("Target time %dms - Time used %dms", targetTime, timer.longValue()));
}
 
開發者ID:mnemonic-no,項目名稱:common-services,代碼行數:23,代碼來源:ServiceMessagingParallellClientServerTest.java

示例9: testDoublesCount

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * A parallel sized stream of doubles generates the given number of values
 */
public void testDoublesCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.doubles(size).parallel().forEach(x -> {
            counter.increment();
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:ThreadLocalRandomTest.java

示例10: testForEachEntryInParallel

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * forEachEntryInParallel traverses all entries
 */
public void testForEachEntryInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachEntry(1L, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:ConcurrentHashMap8Test.java

示例11: testMappedForEachEntrySequentially

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * Mapped forEachEntrySequentially traverses the given
 * transformations of all entries
 */
public void testMappedForEachEntrySequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()),
                               (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:ConcurrentHashMap8Test.java

示例12: testForEachEntrySequentially

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * forEachEntrySequentially traverses all entries
 */
public void testForEachEntrySequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long,Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:ConcurrentHashMap8Test.java

示例13: testUnsizedIntsCount

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * A parallel unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.ints().limit(size).parallel().forEach(x -> counter.increment());
    assertEquals(size, counter.sum());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:ThreadLocalRandom8Test.java

示例14: testUnsizedDoublesCount

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * A parallel unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCount() {
    LongAdder counter = new LongAdder();
    Random r = new Random();
    long size = 100;
    r.doubles().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:RandomTest.java

示例15: newTransaction

import java.util.concurrent.atomic.LongAdder; //導入依賴的package包/類
/**
 * Creates an operation that is part of a bundle.
 * @param input - Operation Input
 * @param bundleLink - Bundle Identifier
 * @param startTime - The start time of the transaction
 * @return Transaction that is part of a Bundle Operation
 * @throws EmptyBodyException - when input is null
 */
static public Transaction newTransaction(OpInput input, Long bundleLink, long startTime)
        throws EmptyBodyException {
    Map.Entry<LongAdder,List<Transaction>> bundleInfo =  (bundleLink != null) ? bundles.get(bundleLink) : null;
    if (bundleInfo == null) {
        bundleInfo = new AbstractMap.SimpleEntry<LongAdder,List<Transaction>>(new LongAdder(),
                new ArrayList<Transaction>());
        bundles.put(bundleLink, bundleInfo);
    }
    return (bundleLink != null) ? new Transaction(input, bundleLink, startTime, bundleInfo) :
                new Transaction(input, startTime);
}
 
開發者ID:opendaylight,項目名稱:fpc,代碼行數:20,代碼來源:Transaction.java


注:本文中的java.util.concurrent.atomic.LongAdder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。