I have a pool of 1000 tasks and want to take a look at them in 100 intervals without having to divide the them into 100-task batches.
You should consider using an ExecutorCompletionService
which allows you to get notified once a single job has finished instead of having to wait for all jobs to complete using invokeAll()
. Then you can put each of the finished jobs into a collection and then act on them when you get 100.
Maybe something like:
CompletionService<Result> ecs = new ExecutorCompletionService<Result>(executor);
for (Callable<Result> s : solvers)
ecs.submit(s);
int n = solvers.size();
List<Result> batch = new ArrayList<Result>();
for (int i = 0; i < n; ++i) {
Result r = ecs.take().get();
batch.add(r);
if (batch.size() >= 100) {
process(batch);
batch.clear();
}
}
if (!batch.isEmpty()) {
process(batch);
}
does the invokeAll() processes the tasks in FIFO manner? That is, are the tasks get started with the order with which they are added to the task list?
The tasks are submitting to the thread-pool in FIFO manner and are dequeued by the threads also in FIFO order. However, once each thread has a job, there are race conditions which may cause some re-ordering of the actual task "start" and certainly finish.