class Philosopher implements Runnable { int id = 0; Resource r = null; public Philosopher(int initId, Resource initr) { id = initId; r = initr; new Thread(this).start(); } public void run() { while (true) { try { System.out.println("Phil " + id + " thinking"); Thread.sleep(30); System.out.println("Phil " + id + " hungry"); r.acquire(id); System.out.println("Phil " + id + " eating"); Thread.sleep(40); r.release(id); } catch (InterruptedException e) { return; } } } }