The difference between Countdownlatch and Cyclicbarrier

Source: Internet
Author: User

See many people on the net the difference between Countdownlatch and Cyclicbarrier is simple to understand that Countdownlatch is a one-time, and cyclicbarrier can continue to use after calling reset. Well, if it's just that simple, I think Cyclicbarrier is simply named Resetablecountdownlatch , which is obviously not.
My understanding is to look at these two classes from their design goals. The description inside the Javadoc is like this.

COUNTDOWNLATCH:A synchronization aid that allows one or more threads to wait until A set of operations being performed in Other threads completes.

CYCLICBARRIER:A synchronization aid that allows a set of threads to all wait for each other to reach A common barrier PO Int.

Maybe my english is not good enough, I feel that it is not easy to understand their differences accurately from this javadoc.
My understanding is that

Countdownlatch: One thread (or more) waits for another n thread to complete something before it can be executed. Cyclicbarrier: N threads wait for each other, and all threads must wait before any one thread finishes.
This should be clear, for Countdownlatch, the focus is the "one thread", it is waiting, and the other n of the thread after the "something" can continue to wait, can be terminated. For Cyclicbarrier, the point is that n threads , either one of them is not finished, and all the threads must wait.

Countdownlatch is the counter, the thread completes one to remember one, just like a count off, just is descending.

And cyclicbarrier more like a sluice, the thread executes like the water, at the gate will be blocked, until the water is full (thread-to-Qi), only to begin to vent the flow.

http://blog.csdn.net/kjfcpua/article/details/7300286

The difference between Countdownlatch and Cyclicbarrier (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.