title: Better way to signal other thread to stop?
body: <p>Started several worker threads , need to notify them to stop. Since some of the threads will sleep for a while before next round of working, need a way which can notify them even when they are sleeping.</p>
  
  <p>If it was Windows programming I could use Event and wait functions. In Java I am doing this by using a CountDownLatch object which count is 1. It works but don't feel elegant, especially I have to check the count value to see if need to exit :</p>
  
  <pre><code>run(){
      while(countDownLatch.count()&gt;0){
              //working
              // ...
              countDownLatch.wait(60,TimeUnit.SECONDS);
      }
  }
  </code></pre>
  
  <p>Semaphore is another choice, but also don't feel very right. I am wondering is there any better way to do this? Thank you.</p>