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

Thread.stop() doesn't prevent thread being started later

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.1.6
    • core-libs
    • generic
    • generic

    Description



      Name: mf23781 Date: 06/12/98


      The Java Language Specification and the JDK documentation clearly
      states that if a thread that has been stopped with Thread.stop()
      is subsequently started with Thread.start(), the thread terminates
      immediately.
      However, in the current implementation of the JDK, the thread executes
      to completion normally instead of being "terminated immediately".

      //
      // In the documentation of Thread.stop(), it states:
      //
      // "It is permitted to stop a thread that has not yet been started.
      // If the thread is eventually started, it immediately terminates."
      //
      //
      // The following code demonstrates that this specification is not implemented.
      // The thread t1 is stopped, then started. It executes to completion and is not
      // "terminated immediately", as per the API documentation.
      //
      // To compile: javac Bug1.java
      //


      public class Bug1 implements Runnable
      {
         public boolean hasRun;

         public Bug1()
         {
            hasRun = false;
         }

         public void run()
         {
            try {
               hasRun = true;
            } finally {
            }
         }

         private static void test()
         {
               Thread t1;
               Bug1 b1;

               b1 = new Bug1();
               t1 = new Thread(b1);

               t1.stop();
               t1.start();

               try {
                  t1.join();
               } catch (InterruptedException e) {
               }

               if (b1.hasRun) {
                  System.err.println("failed...t1 executed after a stop()");
               } else {
                  System.err.println("passed");
               }
         }

         public static void main(String args[])
         {
            test();
         }
      }

      This was originally discovered on AIX 1.1.6, but also occurs on NT JDK 1.1.6,
      1.1.7A, 1.2beta4H.
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              jjb Josh Bloch
              miflemi Mick Fleming
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: