title: Callers block until getFoo() has a value ready?
body: <p>I have a Java <code>Thread</code> which exposes a property which other threads want to access:</p>
  
  <pre><code>class MyThread extends Thread {
     private Foo foo;
     ...
     Foo getFoo() {
       return foo;
     }
     ...
     public void run() { 
       ...
       foo = makeTheFoo();
       ...
     }
  }
  </code></pre>
  
  <p>The problem is that it takes some short time from the time this runs until <code>foo</code> is available. Callers may call <code>getFoo()</code> before this and get a <code>null</code>. I'd rather they simply block, wait, and get the value once initialization has occurred. (<code>foo</code> is never changed afterwards.) It will be a matter of milliseconds until it's ready, so I'm comfortable with this approach.</p>
  
  <p>Now, I can make this happen with <code>wait()</code> and <code>notifyAll()</code> and there's a 95% chance I'll do it right. But I'm wondering how you all would do it; is there a primitive in <code>java.util.concurrent</code> that would do this, that I've missed? </p>
  
  <p>Or, how would you structure it? Yes, make <code>foo</code> volatile. Yes, synchronize on an internal lock <code>Object</code> and put the check in a <code>while</code> loop until it's not <code>null</code>. Am I missing anything?</p>