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

Thread.stop() ignored if called soon after start()

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0.2
    • CPU:
      sparc
    • OS:
      generic
    • Verification:
      Not verified

      Description

      The following extreme test case shows that stop() is ignored if called too
      quickly after start. The program creates a bundle of threads and stops them
      all. After stopping each one it prints the value of isAlive(). For me, I get all
      the threads being reported alive even though all should be reported dead.

      I can imagine there being a concurrency/scheduling problem in stopping
      a thread before it has really been started. However, since the thread has
      already been created, in the worst case, it should be possible to store a boolean
      in the thread state that is checked when appropriate.

      Whatever the problem or solution, this is a serious problem if stop() is really
      to be supported, since in a multi-threaded world, it is difficult to know if the
      call of stop has succeeded or not?

      The test case is extreme in calling stop quite so soon after start, but the test case
      is refined from a real case where a real program was refusing to exit because some
      threads had not died even though they had been stopped.

      -- Jon

      ----------------------------


      public class Bug extends Thread
      {
          public static void main(String[] args) {
              Bug[] bugs = new Bug[10];

              for (int i = 0; i < bugs.length; i++) {
         bugs[i] = new Bug();
      bugs[i].start();
      System.out.println("bugs[" + i + "] = " + bugs[i]);
      bugs[i].stop();
      System.out.println("bugs[" + i + "] " +
      (bugs[i].isAlive() ? "alive" : "dead"));
              }

              System.out.println("main() preparing to exit");
              int n = Thread.activeCount();
      if (n > 0) {
                  System.out.println(n + " threads outstanding");
      Thread[] tarray = new Thread[n];
      n = Thread.enumerate(tarray);
      for (int i = 0; i < n; i++) {
      System.out.println(tarray[i] + " " +
      (tarray[i].isAlive() ? "alive" : "dead"));
      }
      }
              System.out.println("main() really exiting");
          }

          public void run() {
      try {
      wait();
      }
      catch (InterruptedException e) {
      }
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tlindholsunw Timothy Lindholm (Inactive)
              Reporter:
              jjg Jonathan Gibbons
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: