parallele-programmierung/u06-3/Philosopher.java

32 lines
501 B
Java

class Philosopher implements Runnable {
private Table t;
private int id;
public Philosopher(Table t, int id) {
this.t = t;
this.id = id;
}
public void talk() {
System.out.println("Philosopher " + this.id + " is talking.");
}
public void eat() {
System.out.println("Philosopher " + this.id + " is eating.");
}
public void run() {
talk();
try {
t.takeForks(this.id);
} catch (InterruptedException e) {
e.printStackTrace();
}
eat();
t.returnForks(this.id);
}
}