You call future.get()
from within the loop. This method will block until the result is calculated, and therefore the loop will not continue until the other thread is done calculating, resulting in the serialized behavior you get.
To get the behavior you desire, you should have a loop launching all futureTasks on threads, and then a loop getting the results from all the FutureTask
s using get()
.
You're also probably better off submitting a Callable to an ExecutorService (see Executors), and the ExecutorService
will make the Future
for you.
In fact launching calculations in parrallel and waiting for their results is what an ExectorService
's invokeAll()
method does for you.
The use of CountDownLatch
is superfluous, as the Future
objects already have the necessary synchronization behavior on board.