Java main function driver seems to be broken
ApproachThe problem is not with acquiring the locks, its with calling the predefined functions. When not using synchronized to print this, some functions like e
# Approach
The problem is not with acquiring the locks, its with calling the predefined functions. When not using synchronized to print this, some functions like eat.run() are not happening or adding to the ans value, with functions after eat.run() are being added to the ans (thus its not a deadlock issue). If i am mistaken please comment

# Code
```java []
class DiningPhilosophers {

    Semaphore forks[] = new Semaphore[5];

    public DiningPhilosophers() {
        for(int i=0;i<5;i++){
            this.forks[i] = new Semaphore(1);
        }
    }
    public void wantsToEat(int philosopher,
                           Runnable pickLeftFork,
                           Runnable pickRightFork,
                           Runnable eat,
                           Runnable putLeftFork,
                           Runnable putRightFork) throws InterruptedException {
        int left,right;
        right = philosopher;
        left = (philosopher+1)%5;
        if(right==4){
            forks[left].acquire();
            forks[right].acquire();

           synchronized(this){
            pickLeftFork.run();
            pickRightFork.run();
            eat.run();
            putRightFork.run();
            putLeftFork.run();
        }

            forks[right].release();
            forks[left].release();
            return;
        }
        forks[right].acquire();
        forks[left].acquire();
        synchronized(this){
            pickRightFork.run();
            pickLeftFork.run();
            eat.run();
            putRightFork.run();
            putLeftFork.run();
        }
        forks[right].release();
        forks[left].release();
    }
}
```
['Java']