Search in sources :

Example 1 with ForkJoinTask

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

the class ForkJoinPoolTest method testSubmitForkJoinTask.

/**
 * Completed submit(ForkJoinTask) returns result
 */
public void testSubmitForkJoinTask() throws Throwable {
    ForkJoinPool p = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(p);
        ForkJoinTask<Integer> f = p.submit(new FibTask(8));
        assertEquals(21, (int) f.get());
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 2 with ForkJoinTask

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

the class ForkJoinTask8Test method testAbnormalInvokeAllCollection.

private void testAbnormalInvokeAllCollection(ForkJoinPool pool) {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FailingAsyncFib f = new FailingAsyncFib(8);
            AsyncFib g = new AsyncFib(9);
            AsyncFib h = new AsyncFib(7);
            ForkJoinTask<?>[] tasks = { f, g, h };
            shuffle(tasks);
            try {
                invokeAll(Arrays.asList(tasks));
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(f, success);
            }
        }
    };
    testInvokeOnPool(pool, a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) ForkJoinTask(java8.util.concurrent.ForkJoinTask)

Example 3 with ForkJoinTask

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

the class ForkJoinTaskTest method testAbnormalInvokeAll2Singleton.

/**
 * invokeAll(t1, t2) throw exception if any task does
 */
public void testAbnormalInvokeAll2Singleton() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            FailingAsyncFib g = new FailingAsyncFib(9);
            ForkJoinTask<?>[] tasks = { f, g };
            shuffle(tasks);
            try {
                invokeAll(tasks);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(g, success);
            }
        }
    };
    testInvokeOnPool(singletonPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) ForkJoinTask(java8.util.concurrent.ForkJoinTask)

Example 4 with ForkJoinTask

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

the class ForkJoinTaskTest method testAbnormalInvokeAll2.

/**
 * invokeAll(t1, t2) throw exception if any task does
 */
public void testAbnormalInvokeAll2() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            FailingAsyncFib g = new FailingAsyncFib(9);
            ForkJoinTask<?>[] tasks = { f, g };
            shuffle(tasks);
            try {
                invokeAll(tasks);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(g, success);
            }
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) ForkJoinTask(java8.util.concurrent.ForkJoinTask)

Example 5 with ForkJoinTask

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

the class ForkJoinTaskTest method testAbnormalInvokeAll3.

/**
 * invokeAll(tasks) with > 2 argument throws exception if any task does
 */
public void testAbnormalInvokeAll3() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            FailingAsyncFib g = new FailingAsyncFib(9);
            AsyncFib h = new AsyncFib(7);
            ForkJoinTask<?>[] tasks = { f, g, h };
            shuffle(tasks);
            try {
                invokeAll(tasks);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(g, success);
            }
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) ForkJoinTask(java8.util.concurrent.ForkJoinTask)

Aggregations

ForkJoinTask (java8.util.concurrent.ForkJoinTask)10 RecursiveAction (java8.util.concurrent.RecursiveAction)10 ForkJoinPool (java8.util.concurrent.ForkJoinPool)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 ForkJoinWorkerThread (java8.util.concurrent.ForkJoinWorkerThread)1