Search in sources :

Example 46 with RecursiveAction

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

the class RecursiveActionTest method testInForkJoinPool2.

/**
 * inForkJoinPool of non-FJ task returns false
 */
public void testInForkJoinPool2() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            assertFalse(inForkJoinPool());
        }
    };
    assertNull(a.invoke());
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 47 with RecursiveAction

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

the class RecursiveActionTest method testQuietlyInvoke.

/**
 * quietlyInvoke task returns when task completes normally.
 * isCompletedAbnormally and isCancelled return false for normally
 * completed tasks
 */
public void testQuietlyInvoke() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction f = new FibAction(8);
            f.quietlyInvoke();
            assertEquals(21, f.result);
            checkCompletedNormally(f);
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 48 with RecursiveAction

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

the class RecursiveActionTest method testComplete.

/**
 * invoke task suppresses execution invoking complete
 */
public void testComplete() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction f = new FibAction(8);
            f.complete(null);
            assertNull(f.invoke());
            assertEquals(0, f.result);
            checkCompletedNormally(f);
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 49 with RecursiveAction

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

the class RecursiveActionTest method testInvokeAll3.

/**
 * invokeAll(tasks) with > 2 argument invokes tasks
 */
public void testInvokeAll3() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction f = new FibAction(8);
            FibAction g = new FibAction(9);
            FibAction h = new FibAction(7);
            invokeAll(f, g, h);
            assertTrue(f.isDone());
            assertTrue(g.isDone());
            assertTrue(h.isDone());
            checkCompletedNormally(f);
            assertEquals(21, f.result);
            checkCompletedNormally(g);
            assertEquals(34, g.result);
            checkCompletedNormally(g);
            assertEquals(13, h.result);
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 50 with RecursiveAction

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

the class RecursiveActionTest method testReinitialize.

/**
 * A reinitialized normally completed task may be re-invoked
 */
public void testReinitialize() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction f = new FibAction(8);
            checkNotDone(f);
            for (int i = 0; i < 3; i++) {
                assertNull(f.invoke());
                assertEquals(21, f.result);
                checkCompletedNormally(f);
                f.reinitialize();
                checkNotDone(f);
            }
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Aggregations

RecursiveAction (java8.util.concurrent.RecursiveAction)194 CancellationException (java.util.concurrent.CancellationException)19 ExecutionException (java.util.concurrent.ExecutionException)11 ForkJoinTask (java8.util.concurrent.ForkJoinTask)9 HashSet (java.util.HashSet)6 ForkJoinPool (java8.util.concurrent.ForkJoinPool)5 ForkJoinWorkerThread (java8.util.concurrent.ForkJoinWorkerThread)5 CountDownLatch (java.util.concurrent.CountDownLatch)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 TimeoutException (java.util.concurrent.TimeoutException)1