We have three different multi threading techniques in java - Fork/Join pool, Executor Service & CountDownLatch
Fork/Join pool (http://www.javacodegeeks.com/2011/02/java-forkjoin-parallel-programming.html)
The Fork/Join framework is designed to make divide-and-conquer algorithms easy to parallelize. That type of algorithms is perfect for problems that can be divided into two or more sub-problems of the same type. They use recursion to break down the problem to simple tasks until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem
ExecutorService is an interface that extends Executor class and represents an asynchronous execution. It provides us mechanisms to manage the end and detect progress of the asynchronous tasks.
invokeAll() : Executes the given tasks, returning a list of Futures holding their status and results when all complete. Future.isDone() is true for each element of the returned list.
CountDownLatch:(http://examples.javacodegeeks.com/core-java/util/concurrent/countdownlatch-concurrent/java-util-concurrent-countdownlatch-example/)
CountDownLatch is used in synchronisation to allow one or more threads to wait until a set of operations being performed in other threads completes.
My assumption:
In both these alternatives, final result will be known only after completion of all tasks/threads.
Are these three alternatives complimentary or supplementary to each other?
CountDownLatch
is a versatile low-level synchronization primitive, it can be used to synchronize any kind of operations, whereasForkJoin
is a higher level abstraction, specifically made for recursive divide/conquer processing. – SweeneyCountDownLatch
is not a framework. Biziclop called it "versatile". I call it simple as dirt. You can construct one with an initial integer value, you can decrement the value, you can get the value, and you can wait for the value to reach zero (i.e., because of being decremented by other threads). That's all it does. – Microscope