What would be the drawback to invoke many RecursiveAction in the following code?
class RecursiveActionThing extends RecursiveAction {
int numbers = 1000;
public RecursiveActionThing(int numbers)
{
this.numbers = numbers;
}
public void compute()
{
if (numbers<500)
{
for (int i =0;i<numbers;i++)
{
System.out.println(i);
}
}
else{
invokeAll(new RecursiveActionThing(numbers/2),new RecursiveActionThing(numbers/2), new RecursiveActionThing(numbers/2), new RecursiveActionThing(numbers/2));
}
}
}
So far I have only seen invoking 2 tasks, so probably doing the above invocation is going to create a massive overhead in creating all those tasks, however why is it allowed by placing a varargs as paramenter? In certain situation might be useful? Which ones? Thanks in advance.
在jsr166提供的测试类MatrixMultiply.java中有一个很好的例子。您可以在这里找到它
This doesn't make much sense. If you're looking to have a certain number executed you should be able to control it yourself through divide with intervals of 2.
however why is it allowed by placing a varargs as paramenter? In certain situation might be useful? Which ones?
I can't think of any useful reasons this would be used. This is a carry over of the ExecutorService and is just implementing the functionality. I wouldn't recommend it.
Take a look at this question. It doesn't act as well as you would hope.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.