Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. package pcd.mod.pkg3;
  2.  
  3. /**
  4.  *
  5.  * @author VSPC-Infernov4
  6.  */
  7. public class Registro {
  8.  
  9.     private int oficiales = 0;
  10.     private int registrador = 0;
  11.     private int registrador_atiende = 0;
  12.  
  13.     public synchronized void EntraSimple(int id) throws InterruptedException {
  14.         while (oficiales == 3 && registrador == 1) {
  15.             System.out.println("Cliente para nota simple con id " + id + " está esperando.");
  16.             wait();
  17.         }
  18.  
  19.         if (oficiales < 3) {
  20.             oficiales++;
  21.         } else if (registrador==0) {
  22.             registrador++;
  23.             registrador_atiende = id;
  24.         }
  25.  
  26.         System.out.println("Cliente para nota simple con id " + id + " está siendo atendido.");
  27.         System.out.println("Oficiales: " + oficiales + " registrador: " + registrador + "\n");
  28.     }
  29.  
  30.     public synchronized void SaleSimple(int id) {
  31.         if (oficiales <= 3 && registrador_atiende!=id) {
  32.             oficiales--;
  33.         } else {
  34.             registrador--;
  35.         }
  36.         System.out.println("Cliente para nota simple con id " + id + " se va.");
  37.         notifyAll();
  38.         System.out.println("Oficiales: " + oficiales + " registrador: " + registrador + "\n");
  39.     }
  40.  
  41.     public synchronized void EntraPropiedad(int id) throws InterruptedException {
  42.         while (registrador == 1) {
  43.             System.out.println("Cliente para reg. propiedad con id " + id + " está esperando.");
  44.             wait();
  45.         }
  46.  
  47.         oficiales++;
  48.         registrador++;
  49.         System.out.println("Cliente para reg. propiedad con id " + id + " está siendo atendido.");
  50.         System.out.println("Oficiales: " + oficiales + " registrador: " + registrador + "\n");
  51.     }
  52.  
  53.     public synchronized void SalePropiedad(int id) {
  54.         oficiales--;
  55.         registrador--;
  56.        
  57.         System.out.println("Cliente para reg. propiedad con id " + id + " se va.");
  58.         notifyAll();
  59.         System.out.println("Oficiales: " + oficiales + " registrador: " + registrador + "\n");
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement