Countdownlatch Calculator (with callback function)

Source: Internet
Author: User
Final Countdownlatch CDL = new Countdownlatch (1);        New Thread (New Runnable () {            @Override public            void Run () {                try {                    thread.sleep ();                    Cdl.countdown ();                } catch (Exception e) {                    e.printstacktrace ();}}}        ). Start ();        Cdl.await (ten, timeunit.seconds);

Ideas:

Countdownlatch blocks the thread through the await method, the countdown method countdownlatch the value minus 1 per execution, until the Countdownlatch value is 0, and the blocking thread wakes up. The function of some callbacks is accomplished by Countdownlatch this feature.

@ Initialize default assignment of 1

The @CountDownLatch permanently blocks the thread through the await method until the value is 0, through a time-sensitive blocking thread, that is, when the time is timely, the thread is blocked, the time expires, and the blocking thread wakes automatically. This is similar to the 2 methods of inserting and dequeue with time parameters in a queue.

@ In 10s is blocked, as long as the Countdownlatch value is 0, the blocked thread immediately wakes up, starts to continue to execute downward, otherwise it can only continue to block until 10s expires after the blocking thread is automatically awakened.

Countdownlatch Calculator (with callback function)

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.