本文整理匯總了Java中java.util.concurrent.RecursiveTask.fork方法的典型用法代碼示例。如果您正苦於以下問題:Java RecursiveTask.fork方法的具體用法?Java RecursiveTask.fork怎麽用?Java RecursiveTask.fork使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.RecursiveTask
的用法示例。
在下文中一共展示了RecursiveTask.fork方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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()
);
}
示例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);
}