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


Java AtomicInteger.updateAndGet方法代碼示例

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


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

示例1: workerRun

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * Worker run
 */
private void workerRun(Set<Long> uidSet, AtomicInteger control) {
    for (;;) {
        int myPosition = control.updateAndGet(old -> (old == SIZE ? SIZE : old + 1));
        if (myPosition == SIZE) {
            return;
        }

        doGenerate(uidSet, myPosition);
    }
}
 
開發者ID:baidu,項目名稱:uid-generator,代碼行數:14,代碼來源:DefaultUidGeneratorTest.java

示例2: workerRun

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * Woker run
 */
private void workerRun(Set<Long> uidSet, AtomicInteger control) {
    for (;;) {
        int myPosition = control.updateAndGet(old -> (old == SIZE ? SIZE : old + 1));
        if (myPosition == SIZE) {
            return;
        }

        doGenerate(uidSet, myPosition);
    }
}
 
開發者ID:baidu,項目名稱:uid-generator,代碼行數:14,代碼來源:CachedUidGeneratorTest.java

示例3: testConsumerConcurrently

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public void testConsumerConcurrently() throws InterruptedException {
    int expectedNumResults = randomIntBetween(1, 100);
    int bufferSize = randomIntBetween(2, 200);

    SearchRequest request = new SearchRequest();
    request.source(new SearchSourceBuilder().aggregation(AggregationBuilders.avg("foo")));
    request.setBatchedReduceSize(bufferSize);
    InitialSearchPhase.SearchPhaseResults<QuerySearchResultProvider> consumer =
        searchPhaseController.newSearchPhaseResults(request, expectedNumResults);
    AtomicInteger max = new AtomicInteger();
    CountDownLatch latch = new CountDownLatch(expectedNumResults);
    for (int i = 0; i < expectedNumResults; i++) {
        int id = i;
        Thread t = new Thread(() -> {
            int number = randomIntBetween(1, 1000);
            max.updateAndGet(prev -> Math.max(prev, number));
            QuerySearchResult result = new QuerySearchResult(id, new SearchShardTarget("node", new Index("a", "b"), id));
            result.topDocs(new TopDocs(id, new ScoreDoc[0], 0.0F), new DocValueFormat[0]);
            InternalAggregations aggs = new InternalAggregations(Arrays.asList(new InternalMax("test", (double) number,
                DocValueFormat.RAW, Collections.emptyList(), Collections.emptyMap())));
            result.aggregations(aggs);
            consumer.consumeResult(id, result);
            latch.countDown();

        });
        t.start();
    }
    latch.await();
    SearchPhaseController.ReducedQueryPhase reduce = consumer.reduce();
    InternalMax internalMax = (InternalMax) reduce.aggregations.asList().get(0);
    assertEquals(max.get(), internalMax.getValue(), 0.0D);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:33,代碼來源:SearchPhaseControllerTests.java


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