Chapter 14. Building Custom Synchronizers

The class libraries include a number of state-dependent classes—those having operations with state-based preconditions—such as FutureTask, Semaphore, and 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 ...

Get Java Concurrency in Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.