This page has some demonstrations of the JCSP library.  The library itself is available at http://www.cs.kent.ac.uk/projects/ofa/jcsp/.

 

First, here is an executable jar file illustrating the Starving Philosopher Problem.  The code itself was taken from http://www.cs.kent.ac.uk/projects/ofa/java-threads/0.html.  There is a good discussion on this page about the problem in addition to the sample code.  The short of it, however, is that threads who wait() in a synchronized method lose hold of the lock, and are put at the back of the line for getting to use the synchronized method again.

 

This can be fixed using basic constructs from the JCSP library.  My solution is here.

 

There are a few things to note here.  The Canteen class from the original problem has been replaced with a Channel.  Also, the Philosopher and Chef classes no longer extend Thread.  The extent of their synchronization logic is putting data on to the canteenChannel or getting data from it.  This might not seem like a major point, but it means that the synchronization logic is much more contained, and therefore easier to test and verify.

 

Also, I think the code is now much easier to read.  This is perhaps debatable, but take a look and decide for yourself.