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

Thread.join() completes too early

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.5, 1.1.6, 1.2.0, 1.3.0
    • core-libs
    • generic, x86, sparc
    • generic, solaris_2.4, solaris_8, windows_nt



      Name: el35337 Date: 06/04/98


      //
      // Thread.join() completes too early.
      //
      // The documentation for Thread.join() states:
      // "Waits for this thread to die."
      //
      // "thread died" should imply that the instruction pointer associated with the
      // thread never changes again. However, Thread.join() does not implement these semantics.
      //
      // A thread which has been stopped may not die immediately because a finally clause on its
      // stack may be blocked or otherwise delayed for legitimate reasons. However, Thread.join()
      // returns immediately for such threads even if the instruction pointer for the thread will change
      // subsequently (i.e. more code is executed).
      //
      // It seems reasonable that Thread.join() should not complete until the thread is truly dead
      // as opposed to "almost dead" otherwise the caller cannot make any strong assertions about
      // what other concurrent activity may be in progress.
      //
      // To compile: javac Bug2.java
      // To execute: java -classpath .;%CLASSPATH% Bug2
      //


      public class Bug2
      {
         static public class SomeRunnable implements Runnable
         {
            public void run()
            {
               try {
                  System.err.println("run() sleep(5000) begins in " + Thread.currentThread().getName());
                  Thread.sleep(5000);
                  System.err.println("run() exits in " + Thread.currentThread().getName());
               } catch (InterruptedException e) {
               } finally {
                  try {
                     Thread.sleep(3000);
                  } catch (InterruptedException e) {
                  }
                  System.err.println("run() finally clause exits in " + Thread.currentThread().getName());
               }

            }
         }


         public static void main(String args[])
         {
               Thread t1;

               try {

                  t1 = new Thread(new SomeRunnable(), "t1");
                  t1.start();
                  Thread.sleep(2000);
                  t1.stop();
                  t1.join();
                  System.err.println("t1.join completes");
               } catch (InterruptedException i) {
               }
         }
      }
      (Review ID: 32952)
      ======================================================================

            kbr Kenneth Russell (Inactive)
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: