Is it possible to kill a Java thread without raising an exception in it?
This is just for testing purposes – I want to simulate a case when the entire computer dies mid-thread.
Note – I saw a deprecated Thread.destroy() method, but the documentation says it never got implemented in the first place.
No. There is the deprecated, ‘inherently unsafe’
Thread.stop()method, but as its comment emphasizes, things could be left in an deeply corrupted state, and the ThreadDeath Error is still thrown inside the thread.Sun’s explanation of the problems with
stop(), which can manifest long after it appears to work, is at:http://java.sun.com/j2se/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html
Wouldn’t killing the JVM process (or yanking the plug) be a better simulation of computer death?