Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tp8e3;
- import java.time.LocalDateTime;
- import java.util.Random;
- import java.util.concurrent.Semaphore;
- public class Caja extends Thread {
- private final Semaphore DISPONIBLE;
- private final String Nombre;
- public Caja (String nombre, Semaphore disp) {
- this.Nombre= nombre;
- this.DISPONIBLE= disp;
- }
- public void run(){
- Random r = new Random(System.currentTimeMillis());
- try {
- DISPONIBLE.acquire();
- synchronized(this.Nombre) {
- LocalDateTime ahora= LocalDateTime.now();
- System.out.println(this.Nombre +" "+"llego a la caja"+" "+ahora.getHour()+":"+ ahora.getMinute()+":"+ ahora.getSecond());
- Thread.sleep(r.nextInt(2000)+1000);
- System.out.println(this.Nombre +" "+"fue atendido"+" "+ahora.getHour()+":"+ ahora.getMinute()+":"+ ahora.getSecond());}
- }catch (InterruptedException ex){
- ex.printStackTrace();
- }finally {
- DISPONIBLE.release();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement