The class libraries include a number of state-dependent classes—those having operations with state-based preconditions—such as
BlockingQueue. For example, you cannot remove an item from an empty queue or retrieve the result of a task that has not yet finished; before these operations can proceed, you must wait until the queue enters the “nonempty” state or the task enters the “completed” state.
The easiest way to construct a state-dependent class is usually to build on top of an existing state-dependent library class; we did this in
ValueLatch on page 187, using a
CountDownLatch to provide the required blocking behavior. But if the library classes do not provide the functionality ...