title: Avoiding wait/notify in a utility to suspend/resume threads
body: <p>I'm implementing the following Java interface to allow threads to be paused and resumed. I've a working version that uses wait()/notifyAll(), but I wondered if there was an easier way to do it (say, using some nifty widget in java.util.concurrent)?</p>
  
  <pre><code>public interface Suspender {
  
      /**
       * Go into pause mode: any threads which subsequently call maybePause()
       * will block. Calling pause() if already in pause mode has no effect.
       */
      void pause();
  
      /**
       * Leave pause mode: any threads which call maybePause() will not block,
       * and any currently paused threads will be unblocked. Calling resume()
       * if not in pause mode has no effect.
       */
      void resume();
  
      /**
       * If the Suspender is in pause mode, block, and only resume execution
       * when the Suspender is resumed. Otherwise, do nothing.
       */
      void maybePause();
  
  }
  </code></pre>