我必须用来Java Recursive Task (Fork and Join)
计算这样的东西:(3 * 3)^ 2。
我有这个应该可以工作的代码:
public class ForkJoin1 extends RecursiveTask<Long> {
int num;
public ForkJoin1 (int num) {
this.num = num;
}
@Override
protected Long compute() {
if(num == 0) return Long.valueOf(1);
ForkJoin1 fj1 = new ForkJoin1(num*num);
ForkJoin1 fj2 = new ForkJoin1((int) Math.pow(num, 2));
fj1.fork();
return fj1.compute() + fj2.join();
}
public static void main (String[] args) {
ForkJoinPool pool = new ForkJoinPool();
System.out.println("Result: " + pool.invoke(new ForkJoin1(3)));
}
}
我究竟做错了什么?
请注意,我是 Java 中 Recursivetask 的新手。