Programming 2 with Java

Exercise: Producers/Consumers Problem

A number of concurrent threads share a common buffer. The producers produce items and put them into the buffer. The consumers take items from the buffer and consume them. The problem is, that the producers must not put items into the buffer when it is full, and the consumers must not take items from the buffer when it is empty. Furthermore, no threads must access the buffer at the same time.

Producers/Consumers

Implement the Buffer class of the ProducersConsumers program that simulates the producers/consumers problem.

Solution