use of java8.util.concurrent.ForkJoinPool.commonPool in project streamsupport by stefan-zobel.
the class CompletableFutureTest method testDefaultExecutor.
/**
* defaultExecutor by default returns the commonPool if
* it supports more than one thread.
*/
public void testDefaultExecutor() {
CompletableFuture<Integer> f = new CompletableFuture<>();
Executor e = f.defaultExecutor();
Executor c = ForkJoinPool.commonPool();
if (ForkJoinPool.getCommonPoolParallelism() > 1)
assertSame(e, c);
else
assertNotSame(e, c);
}
use of java8.util.concurrent.ForkJoinPool.commonPool in project streamsupport by stefan-zobel.
the class SubmissionPublisherTest method testConstructor1.
/**
* A default-constructed SubmissionPublisher has no subscribers,
* is not closed, has default buffer size, and uses the
* defaultExecutor
*/
public void testConstructor1() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<>();
checkInitialState(p);
assertEquals(p.getMaxBufferCapacity(), Flow.defaultBufferSize());
Executor e = p.getExecutor(), c = ForkJoinPool.commonPool();
if (ForkJoinPool.getCommonPoolParallelism() > 1)
assertSame(e, c);
else
assertNotSame(e, c);
}
use of java8.util.concurrent.ForkJoinPool.commonPool in project streamsupport by stefan-zobel.
the class CustomFJPoolTest method testCustomPools.
public void testCustomPools() throws Exception {
int splitsForP1 = countSplits(new ForkJoinPool(1));
int splitsForP2 = countSplits(new ForkJoinPool(2));
assertEquals(splitsForP2, splitsForP1 * 2);
int commonParallelism = ForkJoinPool.getCommonPoolParallelism();
if (commonParallelism > 1 && commonParallelism < 128) {
int splitsForPHalfC = countSplits(new ForkJoinPool(ForkJoinPool.getCommonPoolParallelism() / 2));
int splitsForPC = countSplits(ForkJoinPool.commonPool());
assertTrue(splitsForPHalfC < splitsForPC);
assertEquals(splitsForPC / splitsForPHalfC, nearestPowerOfTwo(commonParallelism) / nearestPowerOfTwo(commonParallelism / 2));
}
}
Aggregations