Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tp8e3;
- import java.time.LocalDateTime;
- import java.util.concurrent.*;
- public class MainA {
- public static void main(String[] args){
- LocalDateTime ahorai= LocalDateTime.now();
- System.out.println("Inicio:"+" "+ahorai.getHour()+":"+ ahorai.getMinute()+":"+ ahorai.getSecond());
- Semaphore s1 = new Semaphore(1);
- Semaphore s2 = new Semaphore(1);
- Semaphore s3 = new Semaphore(1);
- boolean Demora = true;
- for (int i=0; i<50; i++) {
- boolean t = true;
- while (t){
- if (s1.availablePermits()==1) {
- new Thread (new Caja("Cliente nro"+" "+ i, s1)).start();
- t = false;
- }else {
- if (s2.availablePermits()==1) {
- new Thread (new Caja("Cliente nro"+" "+ i, s2)).start();
- t = false;
- }else {
- if (s3.availablePermits()==1) {
- if (Demora) {
- try{
- Caja.sleep(15000);
- LocalDateTime ahora= LocalDateTime.now();
- System.out.println("Caja 3 habilitada"+" "+ahora.getHour()+":"+ ahora.getMinute()+":"+ ahora.getSecond());
- Demora = false;
- new Thread (new Caja("Cliente nro"+" "+ i, s3)).start();
- t = false;
- }catch(InterruptedException e) {
- e.printStackTrace();
- }
- }else {
- new Thread (new Caja("Cliente nro"+" "+ i, s3)).start();
- t = false;
- }
- }
- }
- }
- }
- }}}
Add Comment
Please, Sign In to add comment