Search in sources :

Example 1 with ForkJoinPool.commonPool

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableFuture(java8.util.concurrent.CompletableFuture) Executor(java.util.concurrent.Executor)

Example 2 with ForkJoinPool.commonPool

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executor(java.util.concurrent.Executor) SubmissionPublisher(java8.util.concurrent.SubmissionPublisher)

Example 3 with ForkJoinPool.commonPool

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));
    }
}
Also used : ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Aggregations

Executor (java.util.concurrent.Executor)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CompletableFuture (java8.util.concurrent.CompletableFuture)1 ForkJoinPool (java8.util.concurrent.ForkJoinPool)1 SubmissionPublisher (java8.util.concurrent.SubmissionPublisher)1