本文整理汇总了Java中java.util.concurrent.RecursiveTask.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java RecursiveTask.invoke方法的具体用法?Java RecursiveTask.invoke怎么用?Java RecursiveTask.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.RecursiveTask
的用法示例。
在下文中一共展示了RecursiveTask.invoke方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: mainThreadExecution
import java.util.concurrent.RecursiveTask; //导入方法依赖的package包/类
/**
* This method is used for main thread (non-multicore) processing.
*
* @return boolean
*/
protected List<Object> mainThreadExecution() {
final List<Object> resultList = new ArrayList<Object>();
for (final RecursiveTask<List<Object>> recursiveTask : this.recursiveTaskList) {
final List<Object> tempList = recursiveTask.invoke();
if (null != tempList) {
resultList.addAll(tempList);
}
}
return resultList;
}