title: How to Block and wait using AtomicBoolean
body: <p>I am looking for a way of pausing a Thread.</p>
  
  <p>I started with affectively using a boolean flag (called 'paused'), and wrapping a check with a while loop (pause). </p>
  
  <p>Within the while loop there’s a <code>Thread.wait()</code> to block the execution.</p>
  
  <p>I’ve been looking at the <strong>AtomicBoolean</strong>, which seems to do the trick apart from it doesn’t block.</p>
  
  <p>Is there a alternative or extended version of AtomicBoolean that has a block method ?</p>
  
  <p>i.e. something like <code>AtomicBoolean.getFalse()</code> of <code>AtomoicBoolean.get(false)</code>? </p>
  
  <p>They have a Blocking Queue, so a Blocking value.</p>
  
  <p>Current setup is :</p>
  
  <pre><code>while (paused.get()) {
          synchronized (paused) {
              try {
  
                  paused.wait();
              } catch (Exception e) {
              }
  
              paused.notify();
          }
      }
  </code></pre>
  
  <p>with </p>
  
  <pre><code>public void pause() {
      if (paused.compareAndSet(false, true)) {
          synchronized (paused) {
              paused.notify();
          }
      }
  
  }
  
  
  public void resume() {
      if (paused.compareAndSet(true, false)) {
          synchronized (paused) {
              paused.notify();
          }
      } 
  }
  </code></pre>