Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
 public boolean pickUp() {
   pause();
   if (!left.pickUp()) {
     return false;
   }
   pause();
   if (!right.pickUp()) {
     left.putDown();
     return false;
   }
   pause();
   return true;
 }
Ejemplo n.º 3
0
 public void putDown() {
   left.putDown();
   right.putDown();
 }