21 lines
485 B
Java
21 lines
485 B
Java
class PhilosophersTest {
|
|
public static void main(String[] args) {
|
|
int numPhilosophers = 5;
|
|
|
|
Thread[] philosophers = new Thread[numPhilosophers];
|
|
Table t = new Table(numPhilosophers);
|
|
|
|
for (int i = 0; i < numPhilosophers; i++) {
|
|
philosophers[i] = new Thread(new Philosopher(t, i));
|
|
philosophers[i].start();
|
|
}
|
|
|
|
for (int i = 0; i < numPhilosophers; i++) {
|
|
try {
|
|
philosophers[i].join();
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
} |