本文整理匯總了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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}