Dining philosophers implementation
<p>I'm just wondering if this all there is to solving the dining philosophers problem in java? </p>

<pre><code>import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MainClass {

public static void main(String[] args) {
    Lock forks[] = new ReentrantLock[5];

    for(int i = 0; i&lt;5; i++){
        forks[i] = new ReentrantLock(); 
    }

    Thread p1 = new Thread(new Philosopher(forks[4], forks[0], "first"));
    Thread p2 = new Thread(new Philosopher(forks[0], forks[1], "second"));
    Thread p3 = new Thread(new Philosopher(forks[1], forks[2], "third"));
    Thread p4 = new Thread(new Philosopher(forks[2], forks[3], "fourth"));
    Thread p5 = new Thread(new Philosopher(forks[3], forks[4], "fifth"));

    p1.start();
    p2.start();
    p3.start();
    p4.start();
    p5.start(); 
  }
}
</code></pre>

<p>and my philosopher class:</p>

<pre><code>import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Philosopher implements Runnable {

Lock leftFork = new ReentrantLock();
Lock rightFork = new ReentrantLock();
String name; 

public Philosopher(Lock leftFork, Lock rightFork, String name) {
    this.leftFork = leftFork;
    this.rightFork = rightFork;
    this.name = name; 
}

@Override
public void run() {

    while(true){
    think(name);
    eat(leftFork, rightFork, name); 
    }
}

private void eat(Lock leftFork, Lock rightFork, String name){
    leftFork.lock();
    rightFork.lock(); 

    System.out.println(name + " eating...");

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
    finally{
        leftFork.unlock();
        rightFork.unlock(); 
        System.out.println(name + " done eating...");
    }
}

private void think(String name){
    System.out.println(name + " thinking...");

    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
}

}
</code></pre>

<p>It feels like there should be more..code. But i've run the program and it does what the problem is asking me to solve. Only two philosophers are eating at any one time, other wise they are thinking. </p>

<p>Do i have this right? </p>
