Monday 30 March 2020

Java Thread CountDownLatch

In case when we want to do some logic until a thread finish (either success or fail), we can use countDownLatch, for instance if we have one thread,
CountDownLatch countDownLatch = new CountDownLatch(1);
jobExecutor = new Thread() {
   @Override public void run() {
      try {
         // core logic
      } catch (Throwable e) {
         //Logger.error
      } finally {
         // count down either success or fail         countDownLatch.countDown();
      }

   } };

// run the thread
jobExecutor.start();
// wait until batch job finishif(countDownLatch != null){
   countDownLatch.await();
}

// other logic when the thread finish running
....

6 comments:


  1. Java Training institute Coimbatore I am mani lives in Chennai. I have read your blog, its really useful for me. I did java development course in coimbatore at reputed java training centre this is useful for me to make a bright career in IT industry. So If anyone want to get best please vist Qtree Technologies.

    ReplyDelete
    Replies
    1. IntelliMindz is the best IT Training in Bangalore with placement, offering 200 and more software courses with 100% Placement Assistance.

      Java Training In Bangalore
      ETL Testing Course In Bangalore
      Power BI Course In Bangalore

      Delete
  2. Breakup is certainly painful and no one wants to go through it. But still if you had a breakup due to any reason, you can still get your ex back, I just got my husband back through the help of genuine love spell caster called dr unity. My name is Emily Sarah am from Tx,USA. My husband left me for another woman, This was just 3 years of our marriage. The most painful thing is that I was pregnant with our second baby. I wanted him back. I did everything within my reach to bring him back but all was in vain, I wanted him back so badly because of the love I had for him, I begged him with everything, I made promises but he refused. I explained my problem to my friend and she suggested that I should rather contact a spell caster that could help me cast a spell to bring him back , I had no choice than to try it. I messaged the spell caster called dr unity, and he assured me there was no problem and that everything will be okay before 11 hours. He cast the spell and surprisingly 11 hours later my husband called me. I was so surprised, I answered the call and all he said was that he was so sorry for everything that had happened He wanted me to return to him. He also said he loved me so much. I was so happy and went to him that was how we started living together happily again.thanks to dr unity . if you are here and your Lover is turning you down, or your husband moved to another woman, do not cry anymore, contact Dr.Unity for help now..Here his contact..WhatsApp him: +2348055361568 ,
    Email him at: Unityspelltemple@gmail.com
    ,Watch this YouTube channel to know how grateful I am https://youtube.com/shorts/rBPtBktMmtA?feature=share

    ReplyDelete
  3. All thanks to Mr Anderson Carl for helping with my profits and making my fifth withdrawal possible. I'm here to share an amazing life changing opportunity with you. its called Bitcoin / Forex trading options. it is a highly lucrative business which can earn you as much as $2,570 in a week from an initial investment of just $200. I am living proof of this great business opportunity. If anyone is interested in trading on bitcoin or any cryptocurrency and want a successful trade without losing notify Mr Anderson Carl now on Whatsapp: +1(252)285-2093 Email: andersoncarlassettrade@gmail.com

    ReplyDelete