Many virtual dining philosophers is a Java implementation of a classic concurrency problem: Dining Philosophers using communicating sequential processes (CSP).
It's an extension of the original one problem, from five to many philosophers.
The purpose of this extension is to compare a Virtual Threads based implementation with a Native Threads based one.
The CSP solution is based on a number of channels. For each philosopher there are two channels, one for the left fork and one for the right fork. To avoid deadlock there is an any to one channel for every philosopher, which is used to signal that the philosopher is done eating. The any to one channel il an n-1 blocking queue, where n is the number of philosophers.
Every philosopher is a virtual thread, which is started by the main thread, which is also the coordinator.
Every philosopher is a native thread, which is started by the main thread, which is also the coordinator.
OpenJDK 20 is required.
- PhilosopherType philosopherType: GREEK for native Threads, GERMAN for virtual Threads
- Integer numberOfPhilosophers
- Long thinkingTime (in milliseconds)
- Long eatingTime (in milliseconds)
- Integer cycles: number of eating cycles for each philosopher