/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Capitulo_8.Almacen;

/**
 *
 * @author felix
 */
public class Almacen {
    private int contenidos;
    private boolean disponible = false;

    public synchronized int get() {
       while (disponible == false) {
          try {
             wait();
          }
          catch (InterruptedException e) {
          }
       }
       disponible = false;
       notifyAll();
       return contenidos;
    }  

    public synchronized void put(int value) {
       while (disponible == true) {
          try {
             wait();
          }
          catch (InterruptedException e) { 
          } 
       }
       contenidos = value;
       disponible = true;
       notifyAll();
    }
}
   
