import java.util.concurrent.Semaphore; /** * Represents an instance of the dining philosophers problem. Contains the philosophers, the forks and a set of threads * to run the philosophers */ public class DiningPhilosophers { private final int numberOfPhilosophers; // number of philosophers at table private Philosopher[] philosophers; // the philosophers private Semaphore[] forks; // the forks private Thread[] t; // the threads that run the philosophers /** * constructs new instance with given number of philosophers * @param numberOfPhilosophers number of philosophers that sit at the table */ public DiningPhilosophers(int numberOfPhilosophers) { this.numberOfPhilosophers = numberOfPhilosophers; // create the forks forks = new Semaphore[numberOfPhilosophers]; for (int i=0; i