Page 1 of 1

About Question enthuware.ocpjp.v7.2.1241 :

Posted: Sat May 18, 2013 11:10 am
by RobynBackhouse
I'm a bit confused by this question.

The question itself states explicitly:
The new value of the element is generated by a utility class's static method, which takes in the existing value as a parameter and returns the new value.
But the answers are RecursiveAction, which does not return a value.
What am I missing here?

:? Confused.com.. :?

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Mon May 20, 2013 5:31 pm
by admin
The utility class's method returns the value that you need to update the array element with. But don't have to return that value from RecursiveAction. Please go through the sample implementation provided in the explanation.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Wed Oct 09, 2013 6:42 am
by Student
Hi,
Why is option 3 not correct?
"Create a RecursiveAction that subdivides the task and submit all such tasks to a ForkJoinPool. "

The answer states "There is no need to submit the sub tasks to the pool. Once you fork a subtask, it is automatically executed by the pool."
ForkJoinTask has the invokeAll methods:

"public static void invokeAll(ForkJoinTask<?>... tasks) ... Forks the given tasks"
"public static <T extends ForkJoinTask<?>> Collection<T> invokeAll(Collection<T> tasks) ...Forks all tasks in the specified collection"

So by dividing a computation into separate chunks and optionally loading it into a collection you you can use your RA subclass instance to invoke those sub tasks.
How is invoking invokeAll on a RA instance not "submitting the tasks to the ForkJoinPool"? A RA exists in a FJP; when you call invokeAll you're saying, "here's a bunch of tasks I want you to execute, go off and execute them" to the FJP. I.e. the FJP is running all the threads; if you call invokeAll you are forking the subtasks and it's the FJP's job to do the forking, isn't it?

Thanks.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Wed Oct 09, 2013 8:18 am
by admin
I am not sure exactly what you mean. Can you put it in code?
Once you submit the first/main RA to FJP, there is no need to submit any other task to FJP. The RA will just fork subtasks, which will be executed by the FJP without explicitly submitting the tasks to it.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Mon Sep 01, 2014 10:47 am
by mcormaechea
Hi! I am really very confused because I cannot understand why is first a fork and then a compute:
newtask2.fork();
newtask1.compute();  
newtask2.join();

Whats the difference between fork and compute methods? Why not invoke two fork() and two join()?

Thanks.
Celeste.-

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Mon Sep 01, 2014 10:50 am
by admin
Please put what you are saying in code, run it, and paste the output so that it will be easier to understand your confusion.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Tue Nov 11, 2014 9:29 am
by Veritas
i don't see any necessity to import java.util.ArrayList and java.util.Arrays in the example

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Tue Nov 11, 2014 12:09 pm
by tanzwud
Agree with answers 5 and 6. However not agree with possible implementation.
There is question about correct compute method.
methods fork and join should be invoked on left side when compute on right side.
newtask1.fork()
newtask2.compute()
newtask1.join()
or
invokeAll(newtask2, newtask1).
Example will work and compile but this is not a correct implementation in my opinion.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Tue Nov 11, 2014 8:16 pm
by admin
tanzwud wrote:Agree with answers 5 and 6. However not agree with possible implementation.
There is question about correct compute method.
methods fork and join should be invoked on left side when compute on right side.
Why do you think so? I don't see any reason why one is better than the other.
-Paul.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Thu Nov 13, 2014 4:22 pm
by tanzwud
Yes my mistake. Seems like it works fine as soon as fork and join on one side and compute on another with no difference in speed.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Wed May 13, 2015 3:49 pm
by ThufirHawat
I don't see where you guys takes out this is a "easy" question in category;

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Fri Jun 26, 2015 12:25 pm
by Alexey Berezkin
Option 3 is a bit misleading. For example, I understood it like "Create a RecursiveAction (implementation details) and submit all such tasks to a ForkJoinPool." In other words, it's like "all such tasks" refer to our RecursiveAction implementation instances, not to subtasks. Though, it may be my problem, of course.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Wed Aug 19, 2015 4:34 pm
by ewebxml
In order for d) (fourth option) to be correct, should it say

Subclass RecursiveTask<V>, implement the compute() method,
and return the new value.

Re: About Question enthuware.ocpjp.v7.2.1241 :

Posted: Thu Aug 20, 2015 8:34 pm
by admin
Updated.
thank you for your feedback!