So the thing is I have an object that does a computationally intensive task.
Assume the main class had two of these objects, I parallelized the process as following.
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
obj1.compute();
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
obj2.compute();
}
});
t1.start();
t2.start();
t1.join();
t2.join();
But if I have an arbitrary number of objects, stored in a list, what would be the best way of doing that? (assume numbers in the magnitude of 10). I was looking into the executor service but could not figure how to rejoin the threads. The ForkJoinPool is supposed to do that, but I could not find how to make it work.
My priority is simple, clear code, rather than performance (since any overhead goes unseen in the 10min the computation takes).