@Override
    public synchronized void put(Integer item) {
        while (isFull()) {
            try {
                wait();
            } catch (InterruptedException ex) {
                System.out.println("Interrupted exception in thread "
                + Thread.currentThread() + " while putting " + item);
                return;
            }
        }
        
        // calculate next free position
        int pos = (newest + 1) % buffer.length;
        buffer[pos] = item;
        newest = pos;
        
        System.out.println(item + " added to buffer");
        
        notifyAll();
    }