Java super concise and self-explained solution
\nclass DiningPhilosophers {\n    private Lock[] locks;\n    \n    public DiningPhilosophers() {\n        locks = new Lock[5];\n        for (int i = 0; i < 5; i
```\nclass DiningPhilosophers {\n    private Lock[] locks;\n    \n    public DiningPhilosophers() {\n        locks = new Lock[5];\n        for (int i = 0; i < 5; i++)\n            locks[i] = new ReentrantLock();\n    }\n\n    public void wantsToEat(int philosopher,\n                           Runnable pickLeftFork,\n                           Runnable pickRightFork,\n                           Runnable eat,\n                           Runnable putLeftFork,\n                           Runnable putRightFork) throws InterruptedException {\n        synchronized(locks) {\n            locks[(philosopher + 1) % 5].lock();\n            locks[philosopher].lock();\n        }  \n        try {\n            pickLeftFork.run();\n            pickRightFork.run();  \n            eat.run();\n            putLeftFork.run();\n            putRightFork.run();\n        } finally {\n            locks[(philosopher + 1) % 5].unlock();\n            locks[philosopher].unlock();\n        }\n    }\n}\n```
[]