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.
KeywordsMain Thread Swing Time Event Queue Clock Tick Action Command
Unable to display preview. Download preview PDF.