Search in sources :

Example 1 with RecursiveAction

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

the class ForkJoinPool8Test method testForkTimedGet.

/**
 * timed get of a forked task returns when task completes
 */
public void testForkTimedGet() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() throws Exception {
            FibAction f = new FibAction(8);
            assertSame(f, f.fork());
            assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
            assertEquals(21, f.result);
            checkCompletedNormally(f);
        }
    };
    checkInvoke(a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 2 with RecursiveAction

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

the class ForkJoinPool8Test method testInvokeAll2.

/**
 * invokeAll(t1, t2) invokes all task arguments
 */
public void testInvokeAll2() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction f = new FibAction(8);
            FibAction g = new FibAction(9);
            invokeAll(f, g);
            checkCompletedNormally(f);
            assertEquals(21, f.result);
            checkCompletedNormally(g);
            assertEquals(34, g.result);
        }
    };
    checkInvoke(a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 3 with RecursiveAction

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

the class ForkJoinPool8Test method testForkGet.

/**
 * get of a forked task returns when task completes
 */
public void testForkGet() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() throws Exception {
            FibAction f = new FibAction(8);
            assertSame(f, f.fork());
            assertNull(f.get());
            assertEquals(21, f.result);
            checkCompletedNormally(f);
        }
    };
    checkInvoke(a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 4 with RecursiveAction

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

the class ForkJoinPool8Test method testInvokeAll1.

/**
 * invokeAll(tasks) with 1 argument invokes task
 */
public void testInvokeAll1() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

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

Example 5 with RecursiveAction

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

the class ForkJoinPool8Test method testJoinIgnoresInterrupts.

/**
 * join/quietlyJoin of a forked task succeeds in the presence of interrupts
 */
public void testJoinIgnoresInterrupts() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction f = new FibAction(8);
            final Thread currentThread = Thread.currentThread();
            // test join()
            assertSame(f, f.fork());
            currentThread.interrupt();
            assertNull(f.join());
            Thread.interrupted();
            assertEquals(21, f.result);
            checkCompletedNormally(f);
            f = new FibAction(8);
            f.cancel(true);
            assertSame(f, f.fork());
            currentThread.interrupt();
            try {
                f.join();
                shouldThrow();
            } catch (CancellationException success) {
                Thread.interrupted();
                checkCancelled(f);
            }
            f = new FibAction(8);
            f.completeExceptionally(new FJException());
            assertSame(f, f.fork());
            currentThread.interrupt();
            try {
                f.join();
                shouldThrow();
            } catch (FJException success) {
                Thread.interrupted();
                checkCompletedAbnormally(f, success);
            }
            // test quietlyJoin()
            f = new FibAction(8);
            assertSame(f, f.fork());
            currentThread.interrupt();
            f.quietlyJoin();
            Thread.interrupted();
            assertEquals(21, f.result);
            checkCompletedNormally(f);
            f = new FibAction(8);
            f.cancel(true);
            assertSame(f, f.fork());
            currentThread.interrupt();
            f.quietlyJoin();
            Thread.interrupted();
            checkCancelled(f);
            f = new FibAction(8);
            f.completeExceptionally(new FJException());
            assertSame(f, f.fork());
            currentThread.interrupt();
            f.quietlyJoin();
            Thread.interrupted();
            checkCompletedAbnormally(f, f.getException());
        }
    };
    checkInvoke(a);
    a.reinitialize();
    checkInvoke(a);
}
Also used : CancellationException(java.util.concurrent.CancellationException) 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