Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Persona extends Thread {
- private int id;
- private Pasillo pasillo;
- private Random random;
- public Persona(int id,Pasillo pasillo) {
- this.id=id;
- this.pasillo=pasillo;
- this.random=new Random();
- }
- public void run() {
- System.out.println("Persona " + id + " hace fila para entrar.");
- try {
- int timePermanency=random.nextInt(700-400)+400;
- synchronized(pasillo) {
- pasillo.entry(id);
- System.out.println("Persona " + id + " está dentro del Zoo por " + timePermanency + "ms.");
- Thread.sleep(timePermanency);
- System.out.println("Persona " + id + " hace fila para salir.");
- pasillo.exit(id);
- }
- System.out.println("Persona " + id + " ha salido del Zoo.");
- }catch(InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment