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


Java ForkJoinTask類代碼示例

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


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

示例1: testCancelledForkJoinCC

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

示例2: testAbnormalInvokeAll3

import java.util.concurrent.ForkJoinTask; //導入依賴的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

示例3: testAbnormalInvokeAllCollection

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

示例4: checkNotDone

import java.util.concurrent.ForkJoinTask; //導入依賴的package包/類
void checkNotDone(ForkJoinTask a) {
    assertFalse(a.isDone());
    assertFalse(a.isCompletedNormally());
    assertFalse(a.isCompletedAbnormally());
    assertFalse(a.isCancelled());
    assertNull(a.getException());
    assertNull(a.getRawResult());
    if (a instanceof BinaryAsyncAction)
        assertEquals(INITIAL_STATE,
                     ((BinaryAsyncAction)a).getForkJoinTaskTag());

    try {
        a.get(randomExpiredTimeout(), randomTimeUnit());
        shouldThrow();
    } catch (TimeoutException success) {
    } catch (Throwable fail) { threadUnexpectedException(fail); }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:ForkJoinTask8Test.java

示例5: testAbnormalInvokeAll2

import java.util.concurrent.ForkJoinTask; //導入依賴的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

示例6: testAbnormalInvokeAll3

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

示例7: testAbnormalInvokeAllCollectionSingleton

import java.util.concurrent.ForkJoinTask; //導入依賴的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

示例8: testAbnormalInvokeAll2

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

示例9: testAbnormalForkTimedGetCC

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

示例10: testAbnormalForkTimedGet

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

示例11: testCancelledForkJoin

import java.util.concurrent.ForkJoinTask; //導入依賴的package包/類
/**
 * join of a forked task throws exception when task cancelled
 */
public void testCancelledForkJoin() {
    ForkJoinTask a = new CheckedRecursiveAction() {
        protected void realCompute() {
            CCF f = new LCCF(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,代碼來源:CountedCompleterTest.java

示例12: testCancelledForkGet

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

示例13: testCancelledForkTimedGet

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

示例14: testInvokeAll3

import java.util.concurrent.ForkJoinTask; //導入依賴的package包/類
/**
 * invokeAll(tasks) with > 2 argument invokes tasks
 */
public void testInvokeAll3() {
    ForkJoinTask a = new CheckedRecursiveAction() {
        protected void realCompute() {
            CCF f = new LCCF(8);
            CCF g = new LCCF(9);
            CCF h = new LCCF(7);
            invokeAll(f, g, h);
            assertEquals(21, f.number);
            assertEquals(34, g.number);
            assertEquals(13, h.number);
            checkCompletedNormally(f);
            checkCompletedNormally(g);
            checkCompletedNormally(h);
        }};
    testInvokeOnPool(mainPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:CountedCompleterTest.java

示例15: testInvokeAllCollection

import java.util.concurrent.ForkJoinTask; //導入依賴的package包/類
/**
 * invokeAll(collection) invokes all tasks in the collection
 */
public void testInvokeAllCollection() {
    ForkJoinTask a = new CheckedRecursiveAction() {
        protected void realCompute() {
            CCF f = new LCCF(8);
            CCF g = new LCCF(9);
            CCF h = new LCCF(7);
            HashSet set = new HashSet();
            set.add(f);
            set.add(g);
            set.add(h);
            invokeAll(set);
            assertEquals(21, f.number);
            assertEquals(34, g.number);
            assertEquals(13, h.number);
            checkCompletedNormally(f);
            checkCompletedNormally(g);
            checkCompletedNormally(h);
        }};
    testInvokeOnPool(mainPool(), a);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:CountedCompleterTest.java


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