O'Reilly logo

Java Concurrency in Practice by Doug Lea, David Holmes, Joseph Bowbeer, Joshua Bloch, Tim Peierls, Brian Goetz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required