1Z0-804 · Question #89
Given the following incorrect program: Which two changes make the program work correctly?
The correct answer is A. Results must be retrieved from the newly created MyTask instances and combined. D. The compute () method must be changed to return an Integer result. Note 1: A RecursiveTask is a recursive result-bearing ForkJoinTask. Note 2: The invokeAll(ForkJoinTask<?>... tasks) forks the given tasks, returning when isDone holds for eachtask or an (unchecked) exception is encountered, in which case the exception is Note 3: Using the…
Question
Given the following incorrect program:
Which two changes make the program work correctly?
Exhibit
Options
- AResults must be retrieved from the newly created MyTask instances and combined.
- BThe threshold value must be increased so that the overhead of task creation does not dominate the
- CThe midpoint computation must be altered so that it splits the workload in an optimal manner.
- DThe compute () method must be changed to return an Integer result.
- EThe compute () method must be enhanced to (fork) newly created tasks.
- FThe myTask class must be modified to extend RecursiveAction instead of RecursiveTask
How the community answered
(44 responses)- A80% (35)
- B2% (1)
- C11% (5)
- E5% (2)
- F2% (1)
Explanation
Note 1: A RecursiveTask is a recursive result-bearing ForkJoinTask. Note 2: The invokeAll(ForkJoinTask<?>... tasks) forks the given tasks, returning when isDone holds for eachtask or an (unchecked) exception is encountered, in which case the exception is Note 3: Using the fork/join framework is simple. The first step is to write some code that performs a segmentof the work. Your code should look similar to this: if (my portion of the work is small enough) do the work directly split my work into two pieces invoke the two pieces and wait for the results Wrap this code as a ForkJoinTask subclass, typically as one of its more specialized types (which can return a result) or RecursiveAction.
Topics
Community Discussion
No community discussion yet for this question.
