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

join(delay) doesn't throw InterruptedException if the thread has died.

XMLWordPrintable

    • sparc
    • solaris_2.4



      Name: akC45999 Date: 06/26/98



      The description of java/lang/Thread.join(long millis) reads:

      Waits at most millis milliseconds for this thread to die.
          A timeout of 0 means to wait forever.
          Parameters:
             millis - the time to wait in milliseconds.
          Throws:
             InterruptedException - if another thread has
             interrupted the current thread.

      So, if the current thread is interrupted, join() has always to throw
      InterruptedException.

      However, Sun's JDK (all versions including 1.2beta4J)
      does not throw InterruptedException if "this" thread has died before the
      call to join().

      In contrast, sleep(long millis) always throws InterruptedException
      even if millis==0.

      --------------------------------- interrupt0104.jasm

      class interrupt0104 extends Thread {
        Thread mainThread=Thread.currentThread();
        volatile boolean issued=false, mustdie=false;

        public void run() {
      mainThread.interrupt();
      issued=true;
      while (!mustdie) Thread.yield();
        }

        public void waitIssued() {
      while (!issued) Thread.yield();
        }

        public void kill() {
      mustdie=true;
      while (isAlive()) Thread.yield();
        }

        static final int DELAY=5000; // millis

        public static void test(boolean killBefore) {
      System.out.print("killBefore="+killBefore+": ");
      interrupt0104 childThread=new interrupt0104();
      try {
      childThread.start();
      childThread.waitIssued();

      if (killBefore) childThread.kill();

      childThread.join(DELAY);
      System.out.println("failed: no InterruptedException");
      childThread.kill();
      } catch (InterruptedException e) {
      System.out.println("passed");
      childThread.kill();
      }
        }

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


      ----------------------------------------
      Running the test:

      novo64% javac interrupt0104.java
      novo64% java -verify interrupt0104
      killBefore=false: passed
      killBefore=true: failed: no InterruptedException
      novo64%

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

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

            collins Gary Collins (Inactive)
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: