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


Java RecursiveTask類代碼示例

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


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

示例1: compute

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
@Override
protected List<WordStatistic> compute() {
    if (lines.size() <= countOfLinesThreshold) {
        return lines.
                stream().
                filter(StringUtils::isNotEmpty).
                map(this::countWordsInLine).
                reduce(Collections.emptyList(), this::mergeWordStatistics);
    }

    RecursiveTask<List<WordStatistic>> recursiveTask = new WordStatisticsInLinesRecursiveTask(lines.subList(0, countOfLinesThreshold), countOfLinesThreshold, wordSeparator);
    recursiveTask.fork();

    return mergeWordStatistics(
            new WordStatisticsInLinesRecursiveTask(lines.subList(countOfLinesThreshold, lines.size()), countOfLinesThreshold, wordSeparator).compute(),
            recursiveTask.join()
    );
}
 
開發者ID:cynicLT,項目名稱:counter-cloud,代碼行數:19,代碼來源:WordStatisticsInLinesRecursiveTask.java

示例2: realMain

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
private static void realMain(String[] args) throws Throwable {
    if (debug) {
        String pp = System.getProperty(
                "java.util.concurrent.ForkJoinPool.common.parallelism");
        System.out.println(
                "java.util.concurrent.ForkJoinPool.common.parallelism:" + pp);
        String tf = System.getProperty(
                "java.util.concurrent.ForkJoinPool.common.threadFactory");
        System.out.println(
                "java.util.concurrent.ForkJoinPool.common.threadFactory:" + tf);
    }

    long from = 0, to = 50000;
    RecursiveTask<Long> task = new SumTask(from, to, Thread.currentThread());
    long sum = task.invoke();
    System.out.printf("%nSum: from [%d] to [%d] = [%d]%n", from, to, sum);

    task.fork();
    sum = task.join();
    System.out.printf("%nSum: from [%d] to [%d] = [%d]%n", from, to, sum);

    sum = ForkJoinPool.commonPool().invoke(task.fork());
    System.out.printf("%nSum: from [%d] to [%d] = [%d]%n", from, to, sum);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:ThreadLessCommon.java

示例3: testAbnormalForkJoin

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * join of a forked task throws exception when task completes abnormally
 */
public void testAbnormalForkJoin() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FailingFibTask f = new FailingFibTask(8);
            assertSame(f, f.fork());
            try {
                Integer r = f.join();
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(f, success);
            }
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:RecursiveTaskTest.java

示例4: testAbnormalForkGet

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

示例5: testAbnormalForkTimedGet

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

示例6: testCancelledInvoke

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * invoke task throws exception when task cancelled
 */
public void testCancelledInvoke() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FibTask f = new FibTask(8);
            assertTrue(f.cancel(true));
            try {
                Integer r = f.invoke();
                shouldThrow();
            } catch (CancellationException success) {
                checkCancelled(f);
            }
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:RecursiveTaskTest.java

示例7: testCancelledForkJoin

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

示例8: testCancelledForkGet

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * get of a forked task throws exception when task cancelled
 */
public void testCancelledForkGet() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() throws Exception {
            FibTask f = new FibTask(8);
            assertTrue(f.cancel(true));
            assertSame(f, f.fork());
            try {
                Integer r = f.get();
                shouldThrow();
            } catch (CancellationException success) {
                checkCancelled(f);
            }
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:RecursiveTaskTest.java

示例9: testCancelledForkTimedGet

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

示例10: testReinitialize

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * A reinitialized normally completed task may be re-invoked
 */
public void testReinitialize() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FibTask f = new FibTask(8);
            checkNotDone(f);

            for (int i = 0; i < 3; i++) {
                Integer r = f.invoke();
                assertEquals(21, (int) r);
                checkCompletedNormally(f, r);
                f.reinitialize();
                f.publicSetRawResult(null);
                checkNotDone(f);
            }
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:RecursiveTaskTest.java

示例11: testReinitializeAbnormal

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * A reinitialized abnormally completed task may be re-invoked
 */
public void testReinitializeAbnormal() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FailingFibTask f = new FailingFibTask(8);
            checkNotDone(f);

            for (int i = 0; i < 3; i++) {
                try {
                    f.invoke();
                    shouldThrow();
                } catch (FJException success) {
                    checkCompletedAbnormally(f, success);
                }
                f.reinitialize();
                checkNotDone(f);
            }
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:RecursiveTaskTest.java

示例12: testCompleteExceptionally

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * invoke task throws exception after invoking completeExceptionally
 */
public void testCompleteExceptionally() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FibTask f = new FibTask(8);
            f.completeExceptionally(new FJException());
            try {
                Integer r = f.invoke();
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(f, success);
            }
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:RecursiveTaskTest.java

示例13: testInvokeAll3

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * invokeAll(tasks) with > 2 argument invokes tasks
 */
public void testInvokeAll3() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FibTask f = new FibTask(8);
            FibTask g = new FibTask(9);
            FibTask h = new FibTask(7);
            invokeAll(f, g, h);
            assertTrue(f.isDone());
            assertTrue(g.isDone());
            assertTrue(h.isDone());
            checkCompletedNormally(f, 21);
            checkCompletedNormally(g, 34);
            checkCompletedNormally(h, 13);
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:RecursiveTaskTest.java

示例14: testInvokeAllCollection

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * invokeAll(collection) invokes all tasks in the collection
 */
public void testInvokeAllCollection() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FibTask f = new FibTask(8);
            FibTask g = new FibTask(9);
            FibTask h = new FibTask(7);
            HashSet set = new HashSet();
            set.add(f);
            set.add(g);
            set.add(h);
            invokeAll(set);
            assertTrue(f.isDone());
            assertTrue(g.isDone());
            assertTrue(h.isDone());
            checkCompletedNormally(f, 21);
            checkCompletedNormally(g, 34);
            checkCompletedNormally(h, 13);
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:RecursiveTaskTest.java

示例15: testAbnormalInvokeAll2

import java.util.concurrent.RecursiveTask; //導入依賴的package包/類
/**
 * invokeAll(t1, t2) throw exception if any task does
 */
public void testAbnormalInvokeAll2() {
    RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
        public Integer realCompute() {
            FibTask f = new FibTask(8);
            FailingFibTask g = new FailingFibTask(9);
            try {
                invokeAll(f, g);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(g, success);
            }
            return NoResult;
        }};
    assertSame(NoResult, testInvokeOnPool(mainPool(), a));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:RecursiveTaskTest.java


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