Oracle's official position Thread.stop()is that it cannot be used. Among other arguments, they write :
Thread.stop()
It should be noted that in all situations when the wait thread does not respond to Thread.interrupt, it also does not respond to Thread.stop.
But I don’t get it. If a thread is actively working on something (and not just waiting or blocking an external resource) and does not explicitly check the interrupt flag, will Thread.interrupt()it not do anything while Thread.stop()it still works (throw ThreadDeath)?
Thread.interrupt()
ThreadDeath
. - ( ) , Thread.interrupt() , Thread.stop() ( throw ThreadDeath)?
, . , , , . , :
-, JVM stop, interrupt.
stop
interrupt
, , ThreadDeath, , , .
Thread.stop , . , . Thread.stop(), () .
, stop() , () (, ): ineterrupt .
POSIX, SIGUSR2 () , /. : . . , : stop() Throwable , Java-. , .
SIGUSR2
, , , .
, Thread.uncaughtExceptionHandler, , .. : .
, , , ThreadDeath , interupt .
Consider this code running in a thread:
public void sellItem(Store s) { synchronized (s) { if (s.itemsAvailable > 0) { s.itemsAvailable--; s.itemsSold++; } } }
If ThreadDeath is called after s.itemsAvailable--, the Store object remains in an inconsistent state. This code, on the other hand, is safe:
s.itemsAvailable--
public void sellLoop(Store s) { while (!Thread.interrupted()) sellItem(s); }
Source: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#stop%28%29
They say that Thread.stop()it will not work, because (I think) throwable can be caught and ignored.
if the JVM is too busy to interrupt the thread, it is also too busy to kill it.