public class MyStackWithGuard extends MyStack {

	public MyStackWithGuard(int size){
		super(size);
    }

    synchronized public boolean isEmpty() {
		return super.isEmpty();
    }

    synchronized public boolean isFull() {
		return super.isFull();
    }

    synchronized public int getSize() {
		return super.getSize();
    }

    synchronized public void push(Object obj) {
		try {
			while (isFull()) {
				wait();
		    }
	    }catch (InterruptedException e) {}
	    super.push(obj);
	    notify();
    }

    synchronized public Object pop() {
		try {
			while (isEmpty()) {
				wait();
		    }
	    } catch (InterruptedException e) {}
	    Object result = super.pop();
	    notify();
	    return result;
	}
	public static void main(String args[]) {
	     MyStackWithGuard stack =
	            new MyStackWithGuard(5);
	        new Producer(stack, 15).start();
	        new Consumer(stack, 15).start();
	}

}