| ||||
Copyright 1999 Sams Publishing |
|
Chapter 5: Gracefully Stopping Threads |
Overview |
In all the examples presented so far in this book, new threads stop running when they die a natural death by returning from the run() method. At times, a thread may be busy doing some involved task for a while (maybe indefinitely) or perhaps may be sleeping for a long time. Sometimes it is necessary to pause or terminate a thread that is executing a lengthy operation whose duration could not be predetermined because of external dependencies like waiting on I/O or for a signal (notification) from another thread. This chapter explores mechanisms used to suspend, resume, and permanently stop a threads execution. This is an area where several methods presented in JDK 1.0 and 1.1 have been deprecated in JDK 1.2. Ill offer alternative techniques to virtually eliminate the necessity to use the deprecated methods . |
| |||
Toc |