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

Thread.interrupt() on InputStream.read() fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.3.1
    • core-libs
    • x86
    • linux

      Name: gm110360 Date: 10/12/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


      uname -a
      Linux <HOSTNAME> 2.4.3-20mdk #1 Sun Apr 15 23:03:10 CEST 2001 i686 unknown


      Thread.interrupt doesn't work for InputStream.read(). This is related to bug
      #4344135, but doesn't involve closing of an underlying socket.
      The program below shows that the thread cannot be interrupted.

      The program works fine under Solaris 8 Update 5 with JDK 1.3.1.



      import java.net.*;

      /** Tests Thread.interrupt() against InputStream.read() */
      public class test2 {

          static class SleeperThread extends Thread {
      public void run() {
      int c;
      try {
      c=System.in.read();
      }
      catch(Exception ex) {
      System.err.println("test2.SleeperThread.run(): " + ex);
      }
      }
          }

          
          public static void main(String[] args) {
      Thread thread;
      final long TIMEOUT=3000;

      thread=new SleeperThread();
      thread.start();
      System.out.println("test2.main(): sleeping for " + TIMEOUT + " msecs");
      try {thread.sleep(TIMEOUT);} catch(Exception e) {}
      System.out.println("test2.main(): sleeping -- done");

      System.out.println("test2.main(): interrupting thread");
      thread.interrupt();
      System.out.println("test2.main(): interrupting thread -- done");

      System.out.println("test2.main(): joining thread (timeout=" + TIMEOUT + "
      msecs)");
      try {thread.join(TIMEOUT);} catch(Exception e) {}
      System.out.println("test2.main(): joining thread -- done");

      System.out.println("test2.main(): thread.isAlive()=" + thread.isAlive());
      if(thread.isAlive()) {
      System.out.println("test2.main(): thread was interrupted but is still
      running !");
      }
          }
      }
      (Review ID: 133623)
      ======================================================================

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: