本文整理匯總了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;
}