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

(process) java.lang.UNIXProcess always waits for 1 second.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.1_003
    • 3.0, 1.1.5, 1.1.6, 1.2.0
    • core-libs
    • b03
    • sparc
    • solaris_2.5.1, solaris_2.6



        Name: eyC74480 Date: 03/10/98


        java.lang.UNIXProcess always waits for 1 second.
        (in both JDK1.1.x and JDK1.2).

        ProcessInputStream within UNIXProcess never flushes
        any read data.
        So user of UNIXProcess has to wait for timeout(1 second).
        This is default manner of java.io.PipedInputStream#receive(int).

        Following is a patch for UNIXProcess.java.
        *** UNIXProcess.java.orig Tue Jan 13 11:26:04 1998
        --- UNIXProcess.java Tue Mar 10 14:51:45 1998
        ***************
        *** 326,331 ****
        --- 326,332 ----
           if ((nread = ins.read(buf)) < 0)
           break;
           outs.write(buf, 0, nread);
        + outs.flush();
           } catch (IOException e) {
           break;
           }

        if you do this patch,
        it works well.
        !qv
        Following program is a test program.
        If you do the program,
        you see that output of echo is always waiting for 1 sec.
        Once you do above patch,
        you will see the output is no longer waiting.


        import java.io.*;

        public class UNIXProcessTest {
            public static void main(String[] args) {
        try {
        String[] commandArray = { "echo.pl" };
        String[] inputStrings = { "abc", "def", "ghi" };
        Process process = Runtime.getRuntime().exec(commandArray);
        DataInputStream in
        = new DataInputStream(process.getInputStream());
        PrintStream out
        = new PrintStream(process.getOutputStream());

        int i = 0;
        int j = 0;
        while (i < 10) {
        System.out.println("sending : "+inputStrings[j]);
        System.out.flush();
        out.println(inputStrings[j]);
        out.flush();
        String line = in.readLine();
        System.out.println("received : "+line);
        System.out.flush();
        j++;
        if (j >= inputStrings.length) {
        j = 0;
        i++;
        }
        }
        out.close();
        } catch (IOException e) {
        e.printStackTrace();
        }
            }
        }
        (Review ID: 26299)
        ======================================================================

              apalanissunw Anand Palaniswamy (Inactive)
              eyusunw Ellis Yu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: