SCJP Study Guide:
Thread


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents
Stopping a Thread

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.

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |