title: How to create a thread that waits for a boolean variable to become true?
body: <p>I have a function that needs to be called once a boolean variable is true. I tried using a while loop in a thread but it doesn't work. Here is what I've tried:</p>
  
  <pre><code>public class MyRunnable implements Runnable {
  
  public void run() {
      while (true) {
           if (conditions == true) { 
               System.out.println("second");
               break;
           }
      }
  }
  
  public static void main(String args[]) {
      boolean condition = false;
      (new Thread(new MyRunnable())).start();
      System.out.println("first\n");
      // set conndition to true
      condition = true;
  
      }
  
  }
  </code></pre>
  
  <p>The result shoud be:</p>
  
  <pre><code>first
  second
  </code></pre>