I am invoking an external JAVA process from my program. I am consuming the output generated by that spawned process like this:
DataInputStream dis = new DataInputStream(new BufferedInputStream(myProcess.getInputStream()));
From a Thread I am doing the following:
while (dis.available() != 0)
{
firstMesg = dis.readLine();
if(firstMesg != null)
{
// processing with the message
//System.out.println(firstMesg);
}
}
try
{
Thread.currentThread().sleep(SLEEP_TIME);
}
catch(Throwable e)
{
}
I was giving SLEEP_TIME around 1 minute and everything was working just fine. Suddenly for a particular setup I have found Sys out (System.out.println) is taking awefully long time from the spawned process.
Can anyone point to me what happened? These two processes must be independent. However the invoker is holding reading from the invoked process. But the buffer should be large where the invoked process is writing. So there is no way it should get blocked.
I can see this in the ProcessBuilder Java doc:
The parent process uses these streams (#getInputStream(), #getErrorStream()) to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.