Christophe De Troyer Christophe De Troyer - 1 month ago 14
Java Question

ForkJoinPool.invokeAll(ArrayList<G extends RecursiveTask<T>)

I'm trying to invoke a list of

RecursiveTask<Double>
instances on a
ForkJoinPool
using
invokeall()
but it's complaining about the types.

I'm not pretty sure why it's not working.

I have the task classes which are defined as follows:

public class WorkerTask<G extends Game> extends RecursiveTask<Double>


I create
n
of these tasks and then I would like to let them loose in a
ForkJoinPool
. I know I can invoke them one by one using
pool.invoke(getValue)
but that's not what I want in the end.

The docs tell me that it has to be a list of objects that implement
Callable
. I followed the type hierarchy upwards up to
ForkJoinTask
. There I can see a class defined
static final class AdaptedCallable<T> extends ForkJoinTask<T>
so I think it should work.

What am I doing wrong here?

Answer

According to the api ForkJoinTask doesn't implement any Callable interface?

Looking at this example I'm not sure you're supposed to be using the invokeAll on the ForkJoinPool. You're supposed to add new WorkerTask to a list in the compute method itself and then call invokeAll(List<WorkerTask>).

Comments