本文整理汇总了Java中java.util.concurrent.ForkJoinPool.awaitQuiescence方法的典型用法代码示例。如果您正苦于以下问题:Java ForkJoinPool.awaitQuiescence方法的具体用法?Java ForkJoinPool.awaitQuiescence怎么用?Java ForkJoinPool.awaitQuiescence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ForkJoinPool
的用法示例。
在下文中一共展示了ForkJoinPool.awaitQuiescence方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAwaitQuiescence1
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* awaitQuiescence by a worker is equivalent in effect to
* ForkJoinTask.helpQuiesce()
*/
public void testAwaitQuiescence1() throws Exception {
final ForkJoinPool p = new ForkJoinPool();
try (PoolCleaner cleaner = cleaner(p)) {
final long startTime = System.nanoTime();
assertTrue(p.isQuiescent());
ForkJoinTask a = new CheckedRecursiveAction() {
protected void realCompute() {
FibAction f = new FibAction(8);
assertSame(f, f.fork());
assertSame(p, ForkJoinTask.getPool());
boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS);
assertTrue(quiescent);
assertFalse(p.isQuiescent());
while (!f.isDone()) {
assertFalse(p.getAsyncMode());
assertFalse(p.isShutdown());
assertFalse(p.isTerminating());
assertFalse(p.isTerminated());
Thread.yield();
}
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
assertFalse(p.isQuiescent());
assertEquals(0, ForkJoinTask.getQueuedTaskCount());
assertEquals(21, f.result);
}};
p.execute(a);
while (!a.isDone() || !p.isQuiescent()) {
assertFalse(p.getAsyncMode());
assertFalse(p.isShutdown());
assertFalse(p.isTerminating());
assertFalse(p.isTerminated());
Thread.yield();
}
assertEquals(0, p.getQueuedTaskCount());
assertFalse(p.getAsyncMode());
assertEquals(0, p.getQueuedSubmissionCount());
assertFalse(p.hasQueuedSubmissions());
while (p.getActiveThreadCount() != 0
&& millisElapsedSince(startTime) < LONG_DELAY_MS)
Thread.yield();
assertFalse(p.isShutdown());
assertFalse(p.isTerminating());
assertFalse(p.isTerminated());
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}
}