Question: We have an implementation of Dinning Philosophers in Java. It includes DiningPhilosophers.java that creates and starts threads, PhilosopherThread.java that starts a thread for each philosopher,

 We have an implementation of Dinning Philosophers in Java. It includesDiningPhilosophers.java that creates and starts threads, PhilosopherThread.java that starts a thread for

We have an implementation of Dinning Philosophers in Java. It includes DiningPhilosophers.java that creates and starts threads, PhilosopherThread.java that starts a thread for each philosopher, and PhilosopherTable java that includes methods pickup() putdown() and test() that look like the following. Fill in the missing code (indicated by - blanki-) public -blank2- void putdown(int i) { setState(i, -blank3-); test(right(i)); testC-blank4-); } public synchronized void pickup(int i) throws InterruptedException { setStateci, State. HUNGRY); -blank1-3 while (state[i] != State. EATING) { this.wait(); // Recheck condition in loop, // since we might have been notified // when we were still hun } private synchronized void test(int i) { if (state[left(i)] != State.EATING && blank5- !=-blank6- && state[i] - State. HUNGRY) } setState(i, -blank7-); // Wake up all waiting threads this.notifyAllo; } } -blank1- [ Choose ] -blank1- -blank2- [Choose ] synchronized left(0) State.EATING State.THINKING state[right] test(i) State.HUNGRY -blank3- -blank4- [Choose ] -blank5- [ Choose -blank6- [Choose ] 4 -blank7- [Choose ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!