private void eat() throws InterruptedException { numberOfMeals++; comments.setText("Philosopher# " + id + " Eating"); comments.setForeground(Color.GREEN); meal.setText("Meal # :" + numberOfMeals); meal.setForeground(Color.BLUE); philLabel.setIcon(DiningPhilosophers.philEatingIcons[id]); Thread.sleep(randomPeriod.nextInt(maxPeriod)); leftChopstick.putDown(); rightChopstick.putDown(); DiningPhilosophers.permissions.release(); DiningPhilosophers.philIsEating[id] = false; }
public boolean pickUp() { pause(); if (!left.pickUp()) { return false; } pause(); if (!right.pickUp()) { left.putDown(); return false; } pause(); return true; }
public void putDown() { left.putDown(); right.putDown(); }