The problem is in your loop:
for (int i = 0; i < coreCount; i++) {
Future<Integer> result = e1.submit(new Count(coreCount, i, charlist));
total += result.get();
}
What this does, is:
- submit a calculation
- call
get()
on theFuture
object, which waits for the calculation to finish - then do the next iteration of the loop
So, in each iteration, your code is waiting for the calculation to be finished before you submit the next one.
You should create two loops, one to submit the calculations, which stores all the Future
objects in a collection, and then a second loop which calls get()
on each of the Future
objects.