Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What modification prevents deadlock in FixedDiningPhilosophers?

  1. Increasing the number of chopsticks

  2. Allowing philosophers to eat with one chopstick

  3. Changing the order of chopstick acquisition for the last philosopher

  4. Providing each philosopher their own chopsticks

The correct answer is: Changing the order of chopstick acquisition for the last philosopher

In FixedDiningPhilosophers, the deadlock occurs because the last philosopher always picks up the left chopstick first, while all the others pick up the right chopstick first. By changing the order of chopstick acquisition for the last philosopher, they can now potentially acquire the right chopstick first and not be stuck waiting for the left chopstick indefinitely. This prevents the deadlock from occurring. The other options do not address the issue of deadlock and will not prevent it from happening.