public class BB_prod-cons { private int BUFFER_SIZE; private E[] buffer; private int in, out; // constructor public BB_prod-cons(int size) { in = 0; out = 0; elements = new E[size]; } // producer calls this method public void insert(E item) { while ((in + 1) % BUFFER_SIZE == out) ; // do nothing -- no free space // add an item to the buffer buffer[in] = item; in = (in + 1) % BUFFER_SIZE; } // consumer calls this method public E remove() { E item; while (in == out) ; // do nothing - nothing to consume // remove an item from the buffer item = buffer[out]; out = (out + 1) % BUFFER_SIZE; return item; } }