Пример #1
0
 public void hungry() throws InterruptedException {
   while (DiningPhilosophers.leftNeighbourPhilosopher(id)
       || DiningPhilosophers.rightNeighbourPhilosopher(id)) {
     Thread.sleep(randomPeriod.nextInt(10));
   }
   DiningPhilosophers.permissions.acquire();
   leftChopstick.pickUp();
   rightChopstick.pickUp();
   DiningPhilosophers.philIsEating[id] = true;
 }
Пример #2
0
 @Override
 public void run() {
   while (DP.in_time() == true) {
     try {
       this.think();
       this.hungry();
       this.eat();
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
 }