當前位置: 首頁>>代碼示例>>Java>>正文


Java RecursiveAction類代碼示例

本文整理匯總了Java中java.util.concurrent.RecursiveAction的典型用法代碼示例。如果您正苦於以下問題:Java RecursiveAction類的具體用法?Java RecursiveAction怎麽用?Java RecursiveAction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RecursiveAction類屬於java.util.concurrent包,在下文中一共展示了RecursiveAction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPollNextLocalTask

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * pollNextLocalTask returns most recent unexecuted task without
 * executing it
 */
public void testPollNextLocalTask() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            AsyncFib g = new AsyncFib(9);
            assertSame(g, g.fork());
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertSame(f, pollNextLocalTask());
            helpQuiesce();
            checkNotDone(f);
            assertEquals(34, g.number);
            checkCompletedNormally(g);
        }};
    testInvokeOnPool(singletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ForkJoinTaskTest.java

示例2: testAbnormalForkGet

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * get of a forked task throws exception when task completes abnormally
 */
public void testAbnormalForkGet() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() throws Exception {
            FailingAsyncFib f = new FailingAsyncFib(8);
            assertSame(f, f.fork());
            try {
                f.get();
                shouldThrow();
            } catch (ExecutionException success) {
                Throwable cause = success.getCause();
                assertTrue(cause instanceof FJException);
                checkCompletedAbnormally(f, cause);
            }
        }};
    testInvokeOnPool(mainPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ForkJoinTaskTest.java

示例3: testAbnormalForkGet

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
public void testAbnormalForkGet(ForkJoinPool pool) {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() throws Exception {
            FailingAsyncFib f = new FailingAsyncFib(8);
            assertSame(f, f.fork());
            try {
                f.get();
                shouldThrow();
            } catch (ExecutionException success) {
                Throwable cause = success.getCause();
                assertTrue(cause instanceof FJException);
                checkCompletedAbnormally(f, cause);
            }
        }};
    testInvokeOnPool(pool, a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ForkJoinTask8Test.java

示例4: testAbnormalInvokeAll2Singleton

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * invokeAll(t1, t2) throw exception if any task does
 */
public void testAbnormalInvokeAll2Singleton() {
    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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ForkJoinTaskTest.java

示例5: testCancelledForkJoinSingleton

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * join of a forked task throws exception when task cancelled
 */
public void testCancelledForkJoinSingleton() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            assertTrue(f.cancel(true));
            assertSame(f, f.fork());
            try {
                f.join();
                shouldThrow();
            } catch (CancellationException success) {
                checkCancelled(f);
            }
        }};
    testInvokeOnPool(singletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ForkJoinTaskTest.java

示例6: testAbnormalInvokeAllCollectionSingleton

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * invokeAll(collection) throws exception if any task does
 */
public void testAbnormalInvokeAllCollectionSingleton() {
    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(singletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ForkJoinTaskTest.java

示例7: testAbnormalInvokeAll3

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * invokeAll(tasks) with > 2 argument throws exception if any task does
 */
public void testAbnormalInvokeAll3() {
    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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ForkJoinTaskTest.java

示例8: testAbnormalInvokeAll2

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
public void testAbnormalInvokeAll2(ForkJoinPool pool) {
    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[0], tasks[1]);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(g, success);
            }
        }};
    testInvokeOnPool(pool, a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ForkJoinTask8Test.java

示例9: testCancelledForkJoin

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * join of a forked task throws exception when task cancelled
 */
public void testCancelledForkJoin() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            assertTrue(f.cancel(true));
            assertSame(f, f.fork());
            try {
                f.join();
                shouldThrow();
            } catch (CancellationException success) {
                checkCancelled(f);
            }
        }};
    testInvokeOnPool(mainPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ForkJoinTaskTest.java

示例10: testGetSurplusQueuedTaskCount

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * getSurplusQueuedTaskCount returns > 0 when
 * there are more tasks than threads
 */
public void testGetSurplusQueuedTaskCount() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            AsyncFib h = new AsyncFib(7);
            assertSame(h, h.fork());
            AsyncFib g = new AsyncFib(9);
            assertSame(g, g.fork());
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertTrue(getSurplusQueuedTaskCount() > 0);
            helpQuiesce();
            assertEquals(0, getSurplusQueuedTaskCount());
            f.checkCompletedNormally();
            g.checkCompletedNormally();
            h.checkCompletedNormally();
        }};
    testInvokeOnPool(singletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:ForkJoinTask8Test.java

示例11: testPeekNextLocalTask

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * peekNextLocalTask returns most recent unexecuted task.
 */
public void testPeekNextLocalTask() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            AsyncFib g = new AsyncFib(9);
            assertSame(g, g.fork());
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertSame(f, peekNextLocalTask());
            assertNull(f.join());
            f.checkCompletedNormally();
            helpQuiesce();
            g.checkCompletedNormally();
        }};
    testInvokeOnPool(singletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ForkJoinTask8Test.java

示例12: testPollNextLocalTaskAsync

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * pollNextLocalTask returns least recent unexecuted task without
 * executing it, in async mode
 */
public void testPollNextLocalTaskAsync() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            AsyncFib g = new AsyncFib(9);
            assertSame(g, g.fork());
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertSame(g, pollNextLocalTask());
            helpQuiesce();
            assertEquals(21, f.number);
            checkCompletedNormally(f);
            checkNotDone(g);
        }};
    testInvokeOnPool(asyncSingletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ForkJoinTaskTest.java

示例13: testGetSurplusQueuedTaskCount

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * getSurplusQueuedTaskCount returns > 0 when
 * there are more tasks than threads
 */
public void testGetSurplusQueuedTaskCount() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            FibAction h = new FibAction(7);
            assertSame(h, h.fork());
            FibAction g = new FibAction(9);
            assertSame(g, g.fork());
            FibAction f = new FibAction(8);
            assertSame(f, f.fork());
            assertTrue(getSurplusQueuedTaskCount() > 0);
            helpQuiesce();
            assertEquals(0, getSurplusQueuedTaskCount());
            checkCompletedNormally(f);
            checkCompletedNormally(g);
            checkCompletedNormally(h);
        }};
    testInvokeOnPool(singletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:RecursiveActionTest.java

示例14: testCancelledForkTimedGetSingleton

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * timed get of a forked task throws exception when task cancelled
 */
public void testCancelledForkTimedGetSingleton() throws Exception {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() throws Exception {
            AsyncFib f = new AsyncFib(8);
            assertTrue(f.cancel(true));
            assertSame(f, f.fork());
            try {
                f.get(LONG_DELAY_MS, MILLISECONDS);
                shouldThrow();
            } catch (CancellationException success) {
                checkCancelled(f);
            }
        }};
    testInvokeOnPool(singletonPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ForkJoinTaskTest.java

示例15: testAbnormalForkGet

import java.util.concurrent.RecursiveAction; //導入依賴的package包/類
/**
 * get of a forked task throws exception when task completes abnormally
 */
public void testAbnormalForkGet() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() throws Exception {
            FailingFibAction f = new FailingFibAction(8);
            assertSame(f, f.fork());
            try {
                f.get();
                shouldThrow();
            } catch (ExecutionException success) {
                Throwable cause = success.getCause();
                assertTrue(cause instanceof FJException);
                checkCompletedAbnormally(f, cause);
            }
        }};
    checkInvoke(a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ForkJoinPool8Test.java


注:本文中的java.util.concurrent.RecursiveAction類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。