This assignment is a modification of Problem 6.31, on page 271 of the course textbook. You will need to understand thread synchronization in Java. See the textbook for a quick review.
Provide a solution to the dining-philosophers problem using Java's condition variables and RMI. Your solution should ensure that no philosopher can starve. I.e., when a philosopher thread blocks, there should be a guaranteed finite amount of time before that philosopher will eat (i.e., the thread will be awakened).
Your five philosopher threads must run on at least two different machines. E.g., you might have two philosopher threads running on one machine, and three on the other.
Submit, via hwmatt,
as many java files as you want, but there must be at least one class called DineMain,
and one called DineRemote. I will run your programs by compiling all the
java files and then doing a java -Djava.security.policy=policy.txt DineMain
YYY on one machine (let XXX be its IP address) and then doing java -Djava.security.policy=policy.txt
DineRemote XXX on the other (let YYY be its IP address). You should submit
a hardcopy of your files at the beginning of class on the due date. Your hardcopy should also contain an explanation of how your program prevents a philosopher from starving.
See my notes for running RMI-based processes.
Philosopher #n is thinking deep thoughts.where n is the philosopher's unique ID, a number between 0 and 4. When a philosopher becomes hungry it should print a message something like:
Philosopher #n is hungry, and looking for chopsticks.When a philosopher begins to eat it should print a message something like:
Philosopher #n has started eating.When the philosopher is done eating it should print a message something like:
Philosopher #n is stuffed! She's placing her chopsticks back on the table.The program output, then, will consist of a sequence of lines like those above. Here's a sample:
Philosopher #0 is thinking deep thoughts.
Philosopher #1 is thinking deep thoughts.
Philosopher #2 is thinking deep thoughts.
Philosopher #3 is thinking deep thoughts.
Philosopher #4 is thinking deep thoughts.
Philosopher #1 is hungry, and looking for chopsticks.
Philosopher #1 has started eating.
Philosopher #3 is hungry, and looking for chopsticks.
Philosopher #3 has started eating.
Philosopher #2 is hungry, and looking for chopsticks.
Philosopher #0 is hungry, and looking for chopsticks.
Philosopher #1 is stuffed! She's placing her chopsticks back
on the table.
Philosopher #2 has started eating.
Philosopher #1 is thinking deep thoughts.
...etc...
Each of the five philosophers should eat 5 times. When all philosophers have eaten 5 times, the program should halt. Each philosopher should remain stuff for a random amount of time between 2 and 5 seconds. When a philosopher eats, it should eat for a random amount of time between 1 and 3 seconds.
Note that the output, above, that pertains to the "remote" philosophers should also appear on the console of the remote machine (the one running DineRemote.)
For up to a full grade bonus (to be applied to any programming project), provide a graphical user interface that represents the philosophers seated around the table, the 5 chopsticks. The appearance of each philosopher's representation (say, its color), should reflect the philospher's state (thinking, eating, hungry), and how many times it has eaten already. In addition, include a widget to control the speed of the simulation, plus a "pause" and "resume" button. The quality of the GUI will determine how much of the full grade extra credit you receive. The graphics should appear on the machine running DineMain.