About Question enthuware.ocpjp.v7.2.1241 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
RobynBackhouse
Posts: 23
Joined: Sun Apr 14, 2013 10:37 am
Contact:

About Question enthuware.ocpjp.v7.2.1241 :

Post 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.. :?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Student
Posts: 53
Joined: Fri Sep 20, 2013 7:20 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

mcormaechea
Posts: 2
Joined: Sat Jul 26, 2014 10:40 am
Contact:

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

Post 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.-

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Veritas
Posts: 12
Joined: Thu Aug 21, 2014 9:34 am
Contact:

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

Post by Veritas »

i don't see any necessity to import java.util.ArrayList and java.util.Arrays in the example

tanzwud
Posts: 19
Joined: Mon Sep 01, 2014 9:45 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

tanzwud
Posts: 19
Joined: Mon Sep 01, 2014 9:45 pm
Contact:

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

Post 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.

ThufirHawat
Posts: 28
Joined: Wed Feb 25, 2015 9:03 am
Contact:

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

Post by ThufirHawat »

I don't see where you guys takes out this is a "easy" question in category;

Alexey Berezkin
Posts: 20
Joined: Fri Jun 19, 2015 9:17 am
Contact:

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

Post 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.

ewebxml
Posts: 78
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Updated.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests