Simple Java solution with one lock and four booleans
\n\nclass DiningPhilosophers {\n\n   // philosopher 0 - forks 4 and 0,\n   // philosopher 1 - forks 0 and 1,\n   // philosopher 2 - forks 1 and 2,\n   // philos
```\n\nclass DiningPhilosophers {\n\n   // philosopher 0 - forks 4 and 0,\n   // philosopher 1 - forks 0 and 1,\n   // philosopher 2 - forks 1 and 2,\n   // philosopher 3 - forks 2 and 3,\n   // philosopher 4 - forks 3 and 4\n   \n   static Object forksLock = new Object();\n   static boolean[] forks = new boolean[5];\n\n   public DiningPhilosophers() {\n       \n   }\n\n   // call the run() method of any runnable to execute its code\n   public void wantsToEat(int philosopher,\n                           Runnable pickLeftFork,\n                           Runnable pickRightFork,\n                           Runnable eat,\n                           Runnable putLeftFork,\n                           Runnable putRightFork) throws InterruptedException {\n      int left = (philosopher == 0) ? 4 : philosopher - 1;\n      int right = philosopher;\n      while (true) {\n         boolean taken = false;\n         synchronized (forksLock) {\n            if (!forks[left] && !forks[right]) {\n               taken = true;\n               forks[left] = true;\n               forks[right] = true;\n            }\n         }\n         if (!taken) {\n            Thread.sleep(1);\n            continue;\n         }\n         pickLeftFork.run();\n         pickRightFork.run();\n         eat.run();\n         putLeftFork.run();\n         putRightFork.run();\n         synchronized (forksLock) {\n               forks[left] = false;\n               forks[right] = false;\n         }\n         break;\n      }\n   }\n}\n```
[]