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; }
@Override public void run() { while (DP.in_time() == true) { try { this.think(); this.hungry(); this.eat(); } catch (InterruptedException e) { e.printStackTrace(); } } }