- Home
- Objectives

- XyzWs Study Guides
- Study Guides
- Study Notes
- Resources

- Mock Exams
SCJP Study Guide:
Thread
Printer-friendly version |
Mail this to a friend
Stopping a Thread
Although the Thread class does contain a stop method, this method is deprecated and should not be used to stop a thread because it is unsafe. Rather, a thread should arrange for its own death by having a run method that terminates naturally. For example, the while loop in this run method is a finite loop: It will iterate a maximun number of times and then exit.
Normally, a thread will end in one of three ways:
- The thread comes to the end of its run() method.
- The thread throws an Exception or Error that is not caught.
- Another thread calls one of the deprecated stop() methods. Deprecated means they still exist, but you shouldn't use them in new code and should strive to eliminate them in existing code.