Timers, Alarms, and Swing Thread Safety

  • Allen Holub


Tins chapter discusses the first of several classes that are useful in multithreaded programming, but which aren’t semaphores. In particular, I’ll talk about timers—objects that help execute some operation at a fixed interval or at some point in the future. I’ll discuss both the timer that is part of the Swing package (called Timer) and also a roll-your-own variety of my own (called Alarm) that is useful when the Swing Timer isn’t available or appropriate. My Alarm implementation is the most complicated of the classes in the book, and it demonstrates several important Java-programming techniques, such as how to write code that needs to suspend and resume threads without using the (now deprecated) suspend() and resume() methods. Along the way, I’ll talk about how to kill a thread gracefully without using the (also deprecated) stop() method.


Main Thread Swing Time Event Queue Clock Tick Action Command 
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

© Allen I. Holub 2000

Authors and Affiliations

  • Allen Holub

There are no affiliations available

Personalised recommendations