Exemplo n.º 1
0
 private void finishEating() {
   rightFork.free();
   leftFork.free();
   System.out.printf("%d Philosopher %d ends eating\n", millis(), id);
   synchronized (lock) {
     lock.notifyAll();
   }
 }
Exemplo n.º 2
0
 private boolean checkAvailableResources() {
   synchronized (lock) {
     if (!leftFork.isOccupied()) {
       leftFork.occupy();
       if (!rightFork.isOccupied()) {
         rightFork.occupy();
         return true;
       } else {
         leftFork.free();
         return false;
       }
     }
     return false;
   }
 }