Luca_G6

MainA.java

May 21st, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package tp8e3;
  2. import java.time.LocalDateTime;
  3. import java.util.concurrent.*;
  4.  
  5. public class MainA {
  6.  
  7.     public static void main(String[] args){
  8.         LocalDateTime ahorai= LocalDateTime.now();
  9.         System.out.println("Inicio:"+" "+ahorai.getHour()+":"+ ahorai.getMinute()+":"+ ahorai.getSecond());
  10.         Semaphore s1 = new Semaphore(1);
  11.         Semaphore s2 = new Semaphore(1);
  12.         Semaphore s3 = new Semaphore(1);
  13.         boolean Demora = true;
  14.         for (int i=0; i<50; i++) {
  15.          boolean t = true;
  16.          while (t){
  17.           if (s1.availablePermits()==1) {
  18.              new Thread (new Caja("Cliente nro"+" "+ i, s1)).start();
  19.              t = false;
  20.           }else {
  21.            if (s2.availablePermits()==1) {
  22.                  new Thread (new Caja("Cliente nro"+" "+ i, s2)).start();
  23.                  t = false;
  24.            }else {
  25.              if (s3.availablePermits()==1) {
  26.                  if (Demora) {
  27.                      try{
  28.                       Caja.sleep(15000);
  29.                       LocalDateTime ahora= LocalDateTime.now();
  30.                       System.out.println("Caja 3 habilitada"+" "+ahora.getHour()+":"+ ahora.getMinute()+":"+ ahora.getSecond());
  31.                       Demora = false;
  32.                       new Thread (new Caja("Cliente nro"+" "+ i, s3)).start();
  33.                       t = false;
  34.                       }catch(InterruptedException e) {
  35.                          e.printStackTrace();
  36.                       }
  37.                 }else {
  38.                         new Thread (new Caja("Cliente nro"+" "+ i, s3)).start();
  39.                         t = false;
  40.                      }
  41.              }
  42.                      
  43.            }
  44.                  
  45.          }
  46.         }
  47.      
  48. }}}
Add Comment
Please, Sign In to add comment