CountDownLatch vs CyclicBarrier vs Semaphore - Java
CountDownLatch CyclicBarrier Semaphore CountDownLatch and CyclicBarrier on the first look seems to do the same task and I read some blogs where they have tried to explain the difference of the two. Most common differences many were saying were; CountDownLatch can not be reused after meeting the final count. CountDownLatch can not be used to wait for Parallel Threads to finish. CyclicBarrier can be reset thus reused CyclicBarrier can be used to wait for Parallel Threads to finish. From these explanation the picture I got was this; If a Main thread creates 5 different thread. CountDownLatch can be used by the Main Thread to wait on the Child Threads. Where as CyclicBarrier can be used to enable waiting on Threads until each other finish. Thus CountDownLatch is a top down waiting where as CyclicBarrier is across waiting. But this wasn't convincing enough for me because no blog clearly explained the practical usage of the two classes. Furthermore there weren't not ...