Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4082713

stop signal issued before thread start is lost.

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic, x86, sparc
    • OS:
      generic, solaris_2.4, windows_nt

      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


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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jjb Josh Bloch
              Reporter:
              rfqsunw Rfq Rfq (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: