Five philosophers sit around a circular table. Each philosopher spends his life alternately thinking and eating. In the centre of the table is a large plate of spaghetti. A philosopher needs two forks to eat a helping of spaghetti. Unfortunately, as philosophy is not as well paid as computing, the philosophers can only afford five forks. One fork is placed between each pair of philosophers and they agree that each will only use the fork to his immediate right and left. The slider in the applet below controls the amount of time that a philosopher spends eating and thinking. Philosophers are depicted in yellow when they are thinking, blue when hungry and green when eating.
The implementation is not deadlock free. (Move the slider all the way to the left to increase the chance of a deadlock.) Modify class RunnablePhilosopher in a way that the deadlock does not occur anymore.
Hint: Analyse the order in which the forks are taken by a philosopher.
Diners.java, Fork.java, PhilTable.java, Philosopher.java, RunnablePhilosopher.java
The result may look like this.