May 2006
Intermediate to advanced
432 pages
12h 21m
English
There is often a tension between safety and liveness. We use locking to ensure thread safety, but indiscriminate use of locking can cause lock-ordering deadlocks. Similarly, we use thread pools and semaphores to bound resource consumption, but failure to understand the activities being bounded can cause resource deadlocks. Java applications do not recover from deadlock, so it is worthwhile to ensure that your design precludes the conditions that could cause it. This chapter explores some of the causes of liveness failures and what can be done to prevent them.
Deadlock is illustrated by the classic, if somewhat unsanitary, “dining philosophers” problem. Five philosophers go out for Chinese food ...