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

(process) Process.waitFor waits for subprocess IO to complete

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.4.2
    • core-libs
    • x86
    • windows_2000

      Name: rl43681 Date: 01/28/2004


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
      and
      java version "1.4.2_03"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
      Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      Runtime.exec() to start a new java program. The new java program should create a socket connection to another program.

      The socket will connect if created and used from the static main method. It will also work if placed in a static method called from main. It will not work if I create an object and have the object execute the same code (which is what I need); it fails both times if the method is static or not static.

      If I run the java program from the command line and not by using Runtime.exec, it works beautifully.

      If while it is blocking I kill the first vm, then the second vm continues.


      ACTUAL -
      Blocking

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class ProgA {
      public static void main(String[] args) throws Exception {
      Runtime rt = Runtime.getRuntime();
      Process p = rt.exec("java ProgB");
      p.waitFor();
      System.out.println("Process Returned");
      }
      }

      ///////////////////////////////////////////////////////////////////////

      import java.net.*;
      import java.io.*;

      public class ProgB {

        public void service() throws Exception {
          //If I move this body of code to main or another static method,
          //the program works.
          Socket s = new Socket("127.0.0.1", 5000); //Blocking
          OutputStream o = s.getOutputStream();
          o.write("test data".getBytes() );
          s.close();
        }

        public static void main(String[] args) throws Exception {
          ProgB b = new ProgB();
          b.service();
        }
      }


      ---------- END SOURCE ----------
      (Incident Review ID: 229305)
      ======================================================================

            martin Martin Buchholz
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: