Relates :
|
|
Relates :
|
|
Relates :
|
There is a potential problem with the new implementation of Thread.stop() used to fix bugs 4145906 and 4145910. If stop() is called on Thread after start() but before it has had a chance to execute its run() method, the stop() can be ignored and the Thread continues to execute. class SimpleThread implements Runnable { SimpleThread() { Thread thread = new Thread(this); thread.start(); System.out.println("Thread.start() returned"); thread.stop(); System.out.println("Thread.stop() returned"); while (thread.isAlive()) { System.out.println("thread is alive"); try { Thread.sleep(100); System.out.println("Waiting for thread to die"); } catch(InterruptedException ie) {} } } public void run() { System.out.println("in run"); try { Thread.sleep(1000); } catch(InterruptedException ie) {} System.out.println("thread finished execution"); } public static void main(String args[]) { new SimpleThread(); } } The following is the output when running JDK1.1.8 build H on an Ultra 1 Sparc (I guess it's possible that the problem may not be easily reproduced on different machines as it is critically dependent on timing): $ /usr/local/java/jdk1.1.8/solaris/bin/java SimpleThread Thread.start() returned Thread.stop() returned thread is alive in run Waiting for thread to die thread is alive Waiting for thread to die thread is alive Waiting for thread to die thread is alive Waiting for thread to die thread is alive Waiting for thread to die thread is alive Waiting for thread to die thread is alive Waiting for thread to die thread is alive Waiting for thread to die thread is alive Waiting for thread to die thread is alive thread finished execution Waiting for thread to die For 1.1.7B, the run() method is never executed: $ /usr/local/java/jdk1.1.7/solaris/bin/java SimpleThread Thread.start() returned Thread.stop() returned stuart.lawrence@eng 1999-03-02
|