The producer/consumer problem is a classical problem in concurrent programming. You have one or more producers of data that store this data in a buffer. You also have one or more consumers of data that take the data from the same buffer. Both producers and consumers share the same buffer, so you have to control access to it to avoid data inconsistency problems. When the buffer is empty, the consumers wait until the buffer has elements. If the buffer is full, the producers wait until the buffer has empty space.
This problem has been implemented using almost all the techniques and synchronization mechanisms developed in Java and in other languages (refer to the See Also section to get more information). One advantage of this problem is that it can be extrapolated to a lot of real-world situations.
The Java 7 Concurrency API introduced...