title: Java Using CountDownLatch to poll a method until a success response
body: <p>I am trying to call a method multiple times every 60 seconds until a success response from the method which actually calls a rest end point on a different service. As of now I am using do while loop and using</p>
  
  <pre><code>Thread.sleep(60000);
  </code></pre>
  
  <p>to make the main thread wait 60 seconds which I feel is not the ideal way due to concurrency issues. </p>
  
  <p>I came across the CountDownLatch method using</p>
  
  <pre><code>CountDownLatch latch = new CountDownLatch(1);
  boolean processingCompleteWithin60Second = latch.await(60, TimeUnit.SECONDS);
  
  @Override
  public void run(){
  
      String processStat = null;
      try {
          status = getStat(processStatId);
          if("SUCCEEDED".equals(processStat))
          {
              latch.countDown();
          }
      } catch (Exception e) {
          e.printStackTrace();
      }   
  }
  </code></pre>
  
  <p>I have the run method in a different class which implements runnable. Not able to get this working. Any idea what is wrong?</p>