当前位置: 首页>>代码示例>>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;未经允许,请勿转载。