本文整理匯總了Java中java.util.concurrent.RecursiveTask.join方法的典型用法代碼示例。如果您正苦於以下問題:Java RecursiveTask.join方法的具體用法?Java RecursiveTask.join怎麽用?Java RecursiveTask.join使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.RecursiveTask
的用法示例。
在下文中一共展示了RecursiveTask.join方法的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: checkCompletesNormally
import java.util.concurrent.RecursiveTask; //導入方法依賴的package包/類
/**
* Waits for the task to complete, and checks that when it does,
* it will have an Integer result equals to the given int.
*/
void checkCompletesNormally(RecursiveTask<Integer> a, int expected) {
Integer r = a.join();
assertEquals(expected, (int) r);
checkCompletedNormally(a, r);
}