/** * A philosopher who thinks, gets hungry and eats with two forks. * * @author Franck van Breugel */ public abstract class Philosopher extends Thread { private int id; private Table table; private Room room; /** * Initialize this philosopher with the given id and table. * * @param id the id of this philosopher. * @param table the table of this philosopher. */ public Philosopher(int id, Table table) { this.id = id; this.table = table; } /** * Life of this philosopher. */ public void run() { while (true) { // think // becomes hungry this.room.enter(); this.table.pickUp(this.id); this.table.pickUp((this.id + 1) % 5); // eat this.table.putDown(this.id); this.table.putDown((this.id + 1) % 5); this.room.leave(); } } }