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