Oracle
1Z0-805 · Question #65
Given: class Fibonacci extends RecursiveTask<Integer> { final int n; Oracle 1Z0-805 Exam Fibonacci (int n) { this.n = n } Integer compute () { if (n <= 1) return n; Fibonacci f1 = new Fibonacci (n…
The correct answer is A. The program produces the correct result, with similar performance to the original. The degree of parallelism is not changed. Functionality is the same.
Concurrency
Question
Given:
class Fibonacci extends RecursiveTask<Integer> { final int n; Oracle 1Z0-805 Exam Fibonacci (int n) { this.n = n } Integer compute () { if (n <= 1) return n; Fibonacci f1 = new Fibonacci (n ?1); f1.fork; // Line X Fibonacci f2 = new Fibonacci (n ?2); // Line Y return f2.compute() + f1.join; } } Suppose that lines X and Y are transposed:
Fibonacci f2 = new Fibonacci (n ?2); // Line Y f1.fork; // Line X What is the likely result?
Options
- AThe program produces the correct result, with similar performance to the original
- BThe program produces the correct result, with performance degraded to the equivalent of being single-threaded.
- CThe program produces an incorrect result
- DThe program goes into an infinite loop
- EAn exception is thrown at runtime
- FThe program produces the correct result, the better performance than the original.
How the community answered
(20 responses)- A70% (14)
- B5% (1)
- C10% (2)
- E15% (3)
Explanation
The degree of parallelism is not changed. Functionality is the same.
Topics
#RecursiveTask#fork/join#task ordering#performance
Community Discussion
No community discussion yet for this question.