jfcmacro

Jardin Limitado con Interface ISync

Mar 28th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. public class JardinLimitado implements ISync {
  2.  
  3.     private int contador;
  4.     final private int maximo = 3;
  5.  
  6.     public JardinLimitado() {
  7.     this.contador = 0;
  8.     }
  9.  
  10.     public synchronized void entrar() {
  11.     try {
  12.         while (contador == maximo) wait();
  13.     } catch (InterruptedException ie) { }
  14.     contador++;
  15.     }
  16.  
  17.     public synchronized void salir() {
  18.     if (contador == maximo) notify();
  19.     contador--;
  20.     }
  21.  
  22.     public synchronized int obtContador() {
  23.     return contador;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment