title: Use value if non-null, otherwise wait and atomically get it, repeat in a loop
body: <p>Suppose a field in an object that changes from null to non-null and back and forth, etc., depending on the operation of <strong>one</strong> thread.</p>
  
  <p>A second thread shall lazily take some action whenever it happens to get hold of a non-null value. In particular the second thread shall wait until the value switches to non-null. If it falls out of the wait, I want to be sure that it has a non-null in its hand.</p>
  
  <p>This does not seem like a queue situation, because the second thread will not take the element away, it just uses it if one happens to be available.</p>
  
  <p>It also does not fit for semaphore use, because again it would not <code>.acquire()</code> a permit. </p>
  
  <p>Rather it reminds of of compare-and-get with built in wait, but this does not seem to exist.</p>
  
  <p>Is there a predefined device for this in <code>java.util.concurrent</code> that I miss to identify. How can this be done?</p>
  
  <p><a href="https://stackoverflow.com/questions/10500703/is-there-a-way-to-wait-for-the-change-on-an-atomic-integer">This</a> is similar but does not have an accepted answer or one that would help here.</p>