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

(thread) Started thread does not terminate immediately if it was stopped before

XMLWordPrintable

    • b57
    • generic, x86
    • generic, windows_xp

      Name: skR10005 Date: 10/25/2001


      The thread does not terminate immediately if it was stopped before it was started.
      The API spec for method Thread.stop reads:
        "It is permitted to stop a thread that has not yet been started. If the thread
         is eventually started, it immediately terminates."

      To reproduce the failure the following simple example can be used:
      =================================================================
      public class test {
          public static void main(String[] argv) {
              A a = new A();
              a.stop();
              a.start();
              try {
                  a.join();
              } catch (Throwable e) {
                  System.out.println("Unexpected exception" + e);
              }
              if(a.state) {
                  System.out.println("Passed");
              } else {
                  System.out.println("Failed");
              }
          }
      }

      class A extends Thread {
        public volatile boolean state = true;
        public void run() {
            state = false;
        }
      }
      =================================================================
      $java -version
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
      $java -cp . test
      Failed


      ======================================================================
      From 6195215 (closed as a dupe of this CR):

      A licensee reports the thread.stop() behavior does not follow the specifications
      in thread.stop() API Document(although stop() is deprecated....)

      According to the API document of thread.stop(),

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

      They hoped "when stopped thread starts , the thread terminates without doing anything."

            psoper Pete Soper (Inactive)
            serjsunw Serj Serj (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: