Search in sources :

Example 11 with ForkJoinPool

use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.

the class ForkJoinPoolTest method testInvokeAny1.

/**
 * invokeAny(null) throws NullPointerException
 */
public void testInvokeAny1() throws Throwable {
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        try {
            e.invokeAny(null);
            shouldThrow();
        } catch (NullPointerException success) {
        }
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 12 with ForkJoinPool

use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.

the class ForkJoinPoolTest method testTimedInvokeAll3.

/**
 * timed invokeAll(c) throws NullPointerException if c has null elements
 */
public void testTimedInvokeAll3() throws InterruptedException {
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        List<Callable<String>> l = new ArrayList<>();
        l.add(new StringTask());
        l.add(null);
        try {
            e.invokeAll(l, randomTimeout(), randomTimeUnit());
            shouldThrow();
        } catch (NullPointerException success) {
        }
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 13 with ForkJoinPool

use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.

the class ForkJoinPoolTest method testInvokeAll1.

/**
 * invokeAll(null) throws NullPointerException
 */
public void testInvokeAll1() throws Throwable {
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        try {
            e.invokeAll(null);
            shouldThrow();
        } catch (NullPointerException success) {
        }
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 14 with ForkJoinPool

use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.

the class ForkJoinPoolTest method testDefaultInitialState.

/**
 * Successfully constructed pool reports default factory,
 * parallelism and async mode policies, no active threads or
 * tasks, and quiescent running state.
 */
public void testDefaultInitialState() {
    ForkJoinPool p = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(p);
        assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory, p.getFactory());
        assertFalse(p.getAsyncMode());
        assertEquals(0, p.getActiveThreadCount());
        assertEquals(0, p.getStealCount());
        assertEquals(0, p.getQueuedTaskCount());
        assertEquals(0, p.getQueuedSubmissionCount());
        assertFalse(p.hasQueuedSubmissions());
        assertFalse(p.isShutdown());
        assertFalse(p.isTerminating());
        assertFalse(p.isTerminated());
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 15 with ForkJoinPool

use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.

the class ForkJoinPoolTest method testTimedInvokeAny3.

/**
 * timed invokeAny(c) throws NullPointerException if c has null elements
 */
public void testTimedInvokeAny3() throws Throwable {
    CountDownLatch latch = new CountDownLatch(1);
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        List<Callable<String>> l = new ArrayList<>();
        l.add(latchAwaitingStringTask(latch));
        l.add(null);
        try {
            e.invokeAny(l, randomTimeout(), randomTimeUnit());
            shouldThrow();
        } catch (NullPointerException success) {
        }
        latch.countDown();
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Aggregations

ForkJoinPool (java8.util.concurrent.ForkJoinPool)55 ExecutorService (java.util.concurrent.ExecutorService)32 RecursiveAction (java8.util.concurrent.RecursiveAction)32 Callable (java.util.concurrent.Callable)20 ArrayList (java.util.ArrayList)15 ExecutionException (java.util.concurrent.ExecutionException)10 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)9 Future (java.util.concurrent.Future)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ForkJoinWorkerThread (java8.util.concurrent.ForkJoinWorkerThread)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ForkJoinTask (java8.util.concurrent.ForkJoinTask)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CancellationException (java.util.concurrent.CancellationException)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Predicate (java8.util.function.Predicate)1