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

FileInputStream.read() blocks the whole JVM instead of just the calling thread.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.1
    • core-libs
    • None
    • sparc
    • solaris_2.5.1



      Name: el35337 Date: 06/24/97


      The following Daemon.java program:
      ----------------------------------------------------------------
      import java.io.*;

      public
      class Daemon
      {
      public static
      void
      main(String[] args)
      {
              PrintStream out = System.out;
              out.print("main: Starting read thread...");
              out.flush();
              new Thread(new Reader(), "Reader").start();
              out.println("done.");
              out.println("main: Calling yield(). Note: Reader thread should block in
      ");
              out.println(" FileInputStream.read() call, so our thread should con
      tinue...");
              Thread.yield();
              out.println("main: Now we are continuing...");
      }
      };

      class Reader
              implements Runnable
      {
      public
      void
      run()
      {
              PrintStream out = System.out;
              try {
                      out.println("reader: Reading one byte...");
                      new FileInputStream(FileDescriptor.in).read();
                      out.println("reader: Read one byte.");
              }
              catch (IOException e) {
                      e.printStackTrace();
              }
      }
      };

      ----------------------------------------------------------------

      when run using the following cmdline:

      { echo "Press ENTER to send one byte:" >&2; read; echo -n s; }|java Daemon

      issues the following output:
      ----------------------------------------------------------------
      Press ENTER to send one byte:
      main: Starting read thread...done.
      main: Calling yield(). Note: Reader thread should block in
            FileInputStream.read() call, so our thread should continue...
      reader: Reading one byte...

      reader: Read one byte.
      main: Now we are continuing...
      ----------------------------------------------------------------


      company - InterSoft Argentina S.A. , email - ###@###.###
      ======================================================================

            mr Mark Reinhold
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: