What is the result of executing the following application? (Choose all that apply.)
import java.util.concurrent.*; public class Main extends RecursiveAction { private int start; private int end; public Main(int start, int end) { this.start = start; this.end = end; } /*from w ww . j a va 2 s .c o m*/ protected void compute() { if (start<0) return; else { int middle = start + ((end-start) / 2); invokeAll(new Main(start, middle), new Main(middle, end)); // m1 } } public static void main(String[] args) { ForkJoinTask<?> task = new Main(0, 4); // m2 ForkJoinPool pool = new ForkJoinPool(); Object result = pool.invoke(task); // m3 } }
E.
The program compiles without issue, so B, C, and D are incorrect.
Lines m2 and m3 throw a compiler warning about generics but still compile.
Notice that RecursiveAction, unlike RecursiveTask, does not return a value.
However, since we used a generic ForkJoinTask reference, the code still compiles.
The issue here is that the base condition is not reached since the numbers start/end are consistently positive.
This causes an infinite loop, although since memory is finite, Java detects this and throws a StackOverflowError, so E is correct.
In practice, this could also generate a locking exception before the StackOverflowError when the program runs out of memory, but in either circumstance, the program will exit.