title: Sleep and check until condition is true
body: <p>Is there a library in Java that does the following? A <code>thread</code> should repeatedly <code>sleep</code> for x milliseconds until a condition becomes true or the max time is reached. </p>
  
  <p>This situation mostly occurs when a test waits for some condition to become true. The condition is influenced by another <code>thread</code>.</p>
  
  <p>[EDIT]Just to make it clearer, I want the test to wait for only X ms before it fails. It cannot wait forever for a condition to become true. I am adding a contrived example.</p>
  
  <pre><code>class StateHolder{
      boolean active = false;
      StateHolder(){
          new Thread(new Runnable(){
              public void run(){
                  active = true;
              }
          }, "State-Changer").start()
      }
      boolean isActive(){
          return active;
      }
  }
  
  
  class StateHolderTest{
      @Test
      public void shouldTurnActive(){
          StateHolder holder = new StateHolder();
          assertTrue(holder.isActive); // i want this call not to fail 
      }
  }
  </code></pre>