Java runtime exec process spontaneously dies

While working on a solution at work, and trying to run one java application 1 I previously made from another java application 2, I had the problem where application 2 would start up, but later spontaneously stopped running.  No amount of changes I made would solve this issue; how I executed, changing arguments passed, or forcing application 1 to sleep a while to try to allow application 2 to finish.

After giving up on it for a while, I finally came across this site explaining that what was happening is basically that the buffers for the output of application 2 were filling up.  In other words:

“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.”

So what needed to be done is consume the stream.  Doing this, and all of a sudden, the application works!

Leave a Reply

Your email address will not be published. Required fields are marked *