-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.5, 1.1.6, 1.2.0
-
generic, x86, sparc
-
generic, solaris_2.4, windows_nt
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
======================================================================
- duplicates
-
JDK-4145906 Thread.stop() not implemented according to documentation
- Closed
-
JDK-4145910 Thread.join() completes too early
- Closed
- relates to
-
JDK-4519200 (thread) Started thread does not terminate immediately if it was stopped before
- Resolved
-
JDK-4216667 Thread.stop() does not always work (problem with fix for 4145910)
- Closed