JDK-4082713 : stop signal issued before thread start is lost.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.5,1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,solaris_2.4,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1997-09-30
  • Updated: 1998-12-16
  • Resolved: 1998-12-16
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description

Name: akC45999			Date: 09/30/97



The specifications of java.lang.Thread reads:

"It is permitted to stop a thread that has not yet been started.
If the thread is eventually started, it immediately terminates." 

Sun's jdk implementations from 1.0.2 to 1.2M ignore the stop signal 
(made by stop() or stop(Throwable) call) if it was made before thread's start.

It is still not clear what "immediately terminates" mean: wether it
means that the child thread wouldn't run at all, or does it mean that
the ThreadDeath (or other exception) will be thrown before the execution
of the very first instruction of the run() method?
Neither explanation seem reasonable.
Thread may be alive or not alive (as indicated by isAlive() method).
Thread.start() makes not alive thread become alive. If Thread.start()
is applied to already alive thread, IllegalThreadStateException is thrown.
Similar, if stop() is applied to a thread which is not alive (e.g. is not started),
same exception should be thrown.

What would the spec people say?

// simplified version of the test
/ javasoft.sqe.tests.api.java.lang.Thread.stop0103;

import java.io.PrintStream;

class stop0103r extends Thread {

  volatile int state=0;
  volatile Throwable exc;

  public void run() {
	try {
		state=1;
	} catch (Throwable t) {
		exc=t;
		state=3;
	}
  }

}


public class stop0103 {

  static final int DELAY=10000;

  public static void main(String args[]) {

	stop0103r thrd=new stop0103r();
	try {
		thrd.stop();
		thrd.stop(new Exception());
		thrd.start();
	} catch (Throwable t) {
		System.out.println("Exception:"+t.getMessage());
		return; 
	}
	try {
		thrd.join(DELAY);
	} catch (InterruptedException t) {
		System.out.println("InterruptedException.");
		return; 
	}
	if (thrd.isAlive()) {
		thrd.stop();
		System.out.println("child thread hangs during "+DELAY+" millisec.");
		return; 
	}
	switch(thrd.state) {
	  case 1:
		System.out.println("stopped thread did not stop");
		return; 
	  case 3:
		System.out.println("Exception in child thread: "+thrd.exc);
		return; 
	}

  }

}

Running the test:
novo37% javac stop0103.java
novo37% setenv CLASSPATH .
novo37% java stop0103
stopped thread did not stop


======================================================================

Comments
EVALUATION Thread.stop is deprecated in 1.2. So I guess this issue is not as pressing as other issues related to java.lang.Thread. Although it is possible to record the fact that a thread has been asked to stop even before it starts, why is this useful at all? I'll reassign this to java/specification so that the spec people can decide what we should do. sheng.liang@Eng 1997-10-16 This is fixed in 1.1.8 by the fix for 4145910. stuart.lawrence@eng 1998-11-13
16-10-1997