title: How to kill a running thread in wait?
body: <p>When i try to kill my Robber threads, some die , but some get stuck in the wait() block , what would be a better way to kill all the threads , or how do i get the blocked threads out to be killed?</p>
  
  <pre><code>private int robberId;
  private static int robberGlobalId=0;
  private TreasureChest chest;
  private boolean alive = true;
  
  public Robber(TreasureChest chest) {
      robberId = robberGlobalId;
      robberGlobalId++;
  
      this.chest = chest;
  }
  
  public void run() {
      while (alive) {
          try {
              synchronized(chest){
                  robCoin();
              }
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
      System.out.println("Robber " +robberId +" just died");
  }
  
  public void robCoin() throws InterruptedException {
      if (chest.getTreasureAmount() &lt;= 0 ) {
          chest.wait();
      } else { 
          chest.removeCoin();
      }
      Thread.sleep(50);
  }
  
  public void killRobber() {
      alive = false;
  }
  </code></pre>