Buffer - put method

Buffer - put method

synchronized public void put(Object o) {

while (count==size) {

try {wait();} catch(InterruptedException e){}

}

buf[in] = o;

++count;

in=(in+1) % size;

notify(); // [count>0]

}

The put method waits if there is no space in the buffer. When an item has been put in the buffer then it notifies a thread which may be waiting to get an item.

Previous slide Next slide Back to the first slide View Graphic Version