A lock may be associated with one or more conditions. These conditions are declared in the
Condition interface. The purpose of these conditions is to allow threads to have control of a lock and check whether a condition is
true or not and, if it's
false, be suspended until another thread wakes them up. The
Condition interface provides the mechanisms to suspend a thread and to wake up a suspended thread.
A classic problem in concurrent programming is the producer-consumer problem. We have a data buffer, one or more producers of data that save it in the buffer, and one or more consumers of data that take it from the buffer as explained earlier in this chapter
In this recipe, you will learn how to implement the ...