当前位置: 首页>>代码示例>>Java>>正文


Java Phaser.arrive方法代码示例

本文整理汇总了Java中java.util.concurrent.Phaser.arrive方法的典型用法代码示例。如果您正苦于以下问题:Java Phaser.arrive方法的具体用法?Java Phaser.arrive怎么用?Java Phaser.arrive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.Phaser的用法示例。


在下文中一共展示了Phaser.arrive方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import java.util.concurrent.Phaser; //导入方法依赖的package包/类
@Test
public void test(){
	ThreadFactory threadFactory = new NamedThreadFactory(null, ScalingThreadPoolExecutorTests.class.getSimpleName(),
			false);
	ThreadPoolExecutor executor = new ScalingThreadPoolExecutor(0, MAX_THREADS, 0, TimeUnit.SECONDS, threadFactory);
	Phaser phaser = new Phaser(1);

	List<Future<?>> futures = new ArrayList<>();
	for(int i = 0; i < MAX_THREADS; i++){
		Assert.assertEquals(executor.getActiveCount(), i);
		Assert.assertEquals(executor.getPoolSize(), i);
		Assert.assertEquals(executor.getQueue().size(), 0);
		phaser.register();
		futures.add(executor.submit(new WaitRunnable(phaser)));
		phaser.arriveAndAwaitAdvance();
	}

	Assert.assertEquals(executor.getActiveCount(), MAX_THREADS);
	Assert.assertEquals(executor.getPoolSize(), MAX_THREADS);
	Assert.assertEquals(executor.getQueue().size(), 0);

	futures.add(executor.submit(new WaitRunnable(phaser)));
	Assert.assertEquals(executor.getActiveCount(), MAX_THREADS);
	Assert.assertEquals(executor.getPoolSize(), MAX_THREADS);
	Assert.assertEquals(executor.getQueue().size(), 1);

	futures.add(executor.submit(new WaitRunnable(phaser)));
	Assert.assertEquals(executor.getActiveCount(), MAX_THREADS);
	Assert.assertEquals(executor.getPoolSize(), MAX_THREADS);
	Assert.assertEquals(executor.getQueue().size(), 2);

	phaser.arrive();
	FutureTool.getAllVaried(futures);

	Assert.assertEquals(executor.getActiveCount(), 0);
	Assert.assertEquals(executor.getCompletedTaskCount(), MAX_THREADS + 2);
	Assert.assertEquals(executor.getQueue().size(), 0);

	executor.shutdownNow();
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:41,代码来源:ScalingThreadPoolExecutorTests.java

示例2: testLeaf

import java.util.concurrent.Phaser; //导入方法依赖的package包/类
void testLeaf() throws Throwable {
    Phaser phaser = new Phaser();
    // this is extremely dependent on internal representation
    stateField.setLong(phaser, ((Integer.MAX_VALUE - 1L) << 32) | 1L);
    checkState(phaser, Integer.MAX_VALUE - 1, 0, 0);
    phaser.register();
    checkState(phaser, Integer.MAX_VALUE - 1, 1, 1);
    phaser.arrive();
    checkState(phaser, Integer.MAX_VALUE, 1, 1);
    phaser.arrive();
    checkState(phaser, 0, 1, 1);
    phaser.arrive();
    checkState(phaser, 1, 1, 1);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:PhaseOverflow.java

示例3: testTiered

import java.util.concurrent.Phaser; //导入方法依赖的package包/类
void testTiered() throws Throwable {
    Phaser root = new Phaser();
    // this is extremely dependent on internal representation
    stateField.setLong(root, ((Integer.MAX_VALUE - 1L) << 32) | 1L);
    checkState(root, Integer.MAX_VALUE - 1, 0, 0);
    Phaser p1 = new Phaser(root, 1);
    checkState(root, Integer.MAX_VALUE - 1, 1, 1);
    checkState(p1, Integer.MAX_VALUE - 1, 1, 1);
    Phaser p2 = new Phaser(root, 2);
    checkState(root, Integer.MAX_VALUE - 1, 2, 2);
    checkState(p2, Integer.MAX_VALUE - 1, 2, 2);
    int ph = Integer.MAX_VALUE - 1;
    for (int k = 0; k < 5; k++) {
        checkState(root, ph, 2, 2);
        checkState(p1, ph, 1, 1);
        checkState(p2, ph, 2, 2);
        p1.arrive();
        checkState(root, ph, 2, 1);
        checkState(p1, ph, 1, 0);
        checkState(p2, ph, 2, 2);
        p2.arrive();
        checkState(root, ph, 2, 1);
        checkState(p1, ph, 1, 0);
        checkState(p2, ph, 2, 1);
        p2.arrive();
        ph = phaseInc(ph);
        checkState(root, ph, 2, 2);
        checkState(p1, ph, 1, 1);
        checkState(p2, ph, 2, 2);
    }
    equal(3, ph);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:PhaseOverflow.java

示例4: xtestTiered

import java.util.concurrent.Phaser; //导入方法依赖的package包/类
void xtestTiered() throws Throwable {
    Phaser root = new Phaser();
    stateField.setLong(root, ((Integer.MAX_VALUE - 1L) << 32) | 1L);
    checkState(root, Integer.MAX_VALUE - 1, 0, 0);
    Phaser p1 = new Phaser(root, 1);
    checkState(root, Integer.MAX_VALUE - 1, 1, 1);
    checkState(p1, Integer.MAX_VALUE - 1, 1, 1);
    Phaser p2 = new Phaser(root, 2);
    checkState(root, Integer.MAX_VALUE - 1, 2, 2);
    checkState(p2, Integer.MAX_VALUE - 1, 2, 2);
    int ph = Integer.MAX_VALUE - 1;
    for (int k = 0; k < 5; k++) {
        checkState(root, ph, 2, 2);
        checkState(p1, ph, 1, 1);
        checkState(p2, ph, 2, 2);
        p1.arrive();
        checkState(root, ph, 2, 1);
        checkState(p1, ph, 1, 0);
        checkState(p2, ph, 2, 2);
        p2.arrive();
        checkState(root, ph, 2, 1);
        checkState(p1, ph, 1, 0);
        checkState(p2, ph, 2, 1);
        p2.arrive();
        ph = phaseInc(ph);
        checkState(root, ph, 2, 2);
        checkState(p1, ph, 1, 1);
        checkState(p2, ph, 2, 2);
    }
    equal(3, ph);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:PhaseOverflow.java

示例5: testPhaseIncrement1

import java.util.concurrent.Phaser; //导入方法依赖的package包/类
/**
 * the phase number increments correctly when tripping the barrier
 */
public void testPhaseIncrement1() {
    for (int size = 1; size < nine; size++) {
        final Phaser phaser = new Phaser(size);
        for (int index = 0; index <= (1 << size); index++) {
            int phase = phaser.arrive();
            assertTrue(index % size == 0 ? (index / size) == phase : index - (phase * size) > 0);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:PhaserTest.java


注:本文中的java.util.concurrent.Phaser.arrive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。