Advanced Multi Threading in Java [ Latch ] - Part 1

CountDown latch is one of the kinds of synchronizer which wait for another thread before performing the tasks or This is used to synchronize one or more tasks by enabling them to wait for the tasks completed by other tasks.  It was introduced in Java 5 along with other CyclicBarrier, Semaphore, CuncurrentHashMap and BlockingQueue. Its somehow like the wait and notify but in the more simpler form and will much less code.

It basically works in the latch principle. Or let us suppose we have a seller who is going to sell 10 (No. of operations) apples. The number of customers may be anything but what the seller is concerned about is the number of apples because when it reaches to 0 he can go home. The seller(Main Thread) will wait for the customers (awaits()). Let's say there are 10 customers(Threads) now who are in the line to buy Apple. When one customer buys that Apple then the number of apple decrease by 1 (countdown()) and another customer will get a chance to buy that apple so on the number of apples goes on decreases and finally become 0. After no apples left in the bucket, the seller can stop selling and go home happily. 

Note:: In CountDown Latch the countdown cannot be reset. 

Image result for CountDownLatch

Let's have a look at Java code::

#HappyCoding #CodingWorkspace


  1. Very impressive article. Hope to see more from you.

  2. Nice post.Thanks for sharing this post .I really appreciate the kind of topics you post here.
    manufacturing erp software in chennai

  3. Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks

    java training in chennai | java training in bangalore

    java online training | java training in pune

    selenium training in chennai

    selenium training in bangalore

  4. This comment has been removed by the author.

  5. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

    angularjs Training in online

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

  6. Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks

    Java Training in Chennai

  7. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    python online training
    python training in OMR
    python training course in chennai

  8. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Devops Training in pune

  9. You are doing a great job. I would like to appreciate your work for good accuracy
    PHP Training in Chennai | PHP Course in Chennai

  10. In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips. I like your writing style and I hope you will keep doing this good working.
    CCNA Course in Chennai
    CCNA Training in Chennai
    DevOps Training in Chennai
    Digital Marketing Training in Chennai
    SEO Training in Chennai
    CCNA Training in Anna Nagar
    CCNA Course in T Nagar

  11. thanks for your information i got information keep sharing web design company in velachery

  12. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it.You’re doing a great job. Keep it up...

    Upgrade your career Learn SAP ABAP Training from industry experts get Complete hands-on Training, Interview preparation, and Job Assistance at Softgen Infotech Located in BTM Layout.

  13. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    artificial intelligence course in hyderabad

  14. Nice blog,I understood the topic very clearly,And want to study more like this.
    Data Scientist Course