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:
...