Suppose a field in an object that changes from null to non-null and back and forth, etc., depending on the operation of one thread.
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.
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.
It also does not fit for semaphore use, because again it would not .acquire()
a permit.
Rather it reminds of of compare-and-get with built in wait, but this does not seem to exist.
Is there a predefined device for this in java.util.concurrent
that I miss to identify. How can this be done?
This is similar but does not have an accepted answer or one that would help here.