In this post, we will see difference between CountDownLatch and CyclicBarrier in java.
Lets first see similarities among them. Both wait for specific number of threads or tasks to finish.
Lets first see similarities among them. Both wait for specific number of threads or tasks to finish.
Lets see differences between CountDownLatch and CyclicBarrier.
CountDownLatch vs CyclicBarrier
Parameter
|
CountDownLatch
|
CyclicBarrier
|
---|---|---|
Reuse
|
It can not be reused once count reaches 0
|
It can be reinitialized once parties reaches to 0, so it can reused
|
MethodÂ
|
It calls countDown() method to reduce the counter
|
It calls await() method to reduce the counter.
|
Common Event
|
It can not trigger common event when count reaches 0
|
It can trigger common event (Runnable) once reaches to a barrier point. Constructor :CyclicBarrier(int parties, Runnable barrierAction)
|
Constructor
|
CountDownLatch(int count) |
CyclicBarrier(int parties)
|
You can go through core java interview questions for beginners and experienced for more such questions.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.