Duplicate :
|
Method Thread.stop() does not nesessary stops a thread but only causes an exception to be thrown on this thread. This exception can be intercepted and the thread can cantinue executionm However, in all jdk1.1.* releases, Thread.stop() immediately marks the object thread as not alive. Thread.stop(Throwable) does it too. Testcase: import java.io.PrintStream; class DeadOrAliveE extends Error {} public class DeadOrAlive { static PrintStream out=System.out; public static void main(String args[]) { Thread me=Thread.currentThread(); try { // me.stop(new DeadOrAliveE()); me.stop(); // } catch (DeadOrAliveE e) { } catch (ThreadDeath e) { if (me.isAlive()) { out.println("OK"); } else { out.println("isAlive()==false for running thread"); } return; } catch (Throwable e) { out.println("wrong Throwable:"+e); } out.println("no Throwable thrown after stop"); } } % javac DeadOrAlive.java % java -fullversion java full version "JDK1.1.8M" % java DeadOrAlive isAlive()==false for running thread