title: Best synchronization strategy to block worker threads when a database is down
body: <p>Multiple workers are processing from a queue and when a database failure occurs it will contact a supervisor that will then lock all worker threads and poll the database at an interval until it is up and it will then release all the threads so they can continue processing. The worker threads can either advance or wait with the processing and the supervisor thread can lock or unlock. </p>
  
  <p>I was thinking of an interface like this. What synchronization primitives would you use? Actors would be a good solution but i don't have the time for a rewrite.</p>
  
  <pre><code>public interface Latch {
  
      /**
       * This method will cause a thread(s) to only advance if the latch is in an open state. If the
       * latch is closed the thread(s) will wait until the latch is open before they can advance.
       */
      void advanceWhenOpen();
  
      /**
       * Close the latch forcing all threads that reaches the latch's advance method to wait until
       * its open again.
       */
      void close();
  
      /**
       * Opens the latch allowing blocked threads to advance.
       */
      void open();
  
      boolean isOpen();
  }
  </code></pre>