Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Threads always preserve class invariants when they are allowed to exit normally, as long as the specification is followed. Programmers often try to forcefully terminate threads when they believe that the task is accomplished, the request has been canceled or the program or JVM needs to quickly shutdownshut down.

A few thread APIs were introduced to facilitate thread suspension, resumption and termination but were later deprecated because of inherent design weaknesses. The Thread.stop() method is one example. It throws a ThreadDeath exception to stop the thread. Two cases arise:

...