Chapter 13. Implementing concurrency control

 

This chapter covers

  • Ensuring Swing’s thread-safety rule
  • Improving responsiveness of UI applications
  • Implementing a reusable read-write lock pattern

If the commonplace usage of multicore processors, the advent of specialized languages such as Erlang and Haskell, the heated discussions in developer communities, and the popularity of books on the subject are any indication, software systems are rapidly embracing ever-higher levels of concurrency. Yet concurrency control remains a mysterious topic to many developers. Even when you gain sufficient knowledge, implementing a concurrency-control scheme correctly and consistently is extremely complex because the implementation spans multiple modules. This can lead to poorly implemented systems with visual anomalies, mysterious crashes, compromised data integrity, and deadlocks—all embarrassingly common problems.

Concurrency control is best implemented using appropriate design patterns. Instead of analyzing ad hoc implementations, you start with proven ways to address thread safety and liveliness problems. A pattern, for example, can specify when and how to obtain locks on an object to avoid deadlocks, provide maximum concurrency, and minimize overhead. Of course, each pattern suits a particular kind of problem, and you must analyze your problem to choose the right pattern.

13.1. Modularizing Swing’s single-thread rule

13.2. Improving the responsiveness of UI applications

13.3. Modularizing the read-write lock pattern

13.4. Summary