In this chapter, we discussed some of the possibilities available to you when using threads, and we pointed out some trouble spots to avoid. We discussed safe threading issues, threads and Swing, blocking, waiting, and a host of other topics.

The best way to understand threading is to design your threading scheme, make predictions about how it will function, and then test those predictions with the handy method in the Thread class, holdsLock(Object). Thread’s getState() and getStackTrace() methods can be very handy for checking what another thread is doing. If your threads aren’t behaving the way you expected them to, explicitly record your assumptions (we suggest writing them down) and then examine them one by one. Threading is a lot like grammar: There are a lot of rules, but eventually you develop a sense for what works and what doesn’t. (Or so I’m told.)

As you read the next chapters, please don’t hesitate to refer back to this chapter when needed.


Race Condition Main Thread Automate Teller Machine Collection Plate Member Variable 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Copyright information

© Andrew Monkhouse and Terry Camerlengo 2006

Personalised recommendations