tags:

views:

34

answers:

2

Hi, I have a java application running on Solaris. This application regularily launches external processes using Runtime.exec. It seems that after a while, having successfully launched such processes many time over, a launching of a process will hang. A thread dump taken at this point (and several minutes later) reveals that java.lang.UNIXProcess.forkAndExec is "stuck". Following is the top of the relevant stack trace taken from the thread dump:

"Thread-85305" prio=3 tid=0x0000000102aae800 nid=0x21499 runnable [0x7fffffff2a3fe000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)

I have read through some forums where others have experienced forAndExec throwing an IOException due to not enough space or not enough memory, but I'm not getting this error here. I'm now waiting to get the results of pstack in the hope that it will reveal more information.

Does anyone have any idea on how to resolve this issue? thanks, Mike

A: 

As the thread live as long as your executable is running, maybe it's only your external executable which is hanging.

You should try to find the parameters passed to your executable and try to launch it manually.

Colin Hebert
But as far as I'm aware, Runtime.exec() is asyncronous wrt the external process. In other words, normally after Runtime.exec() returns, inter process communication will successfully take place with the running external process.
Mike
A: 

Is stdout and stderr from the process being consumed? You might be looking at the results of a full buffer.

You can test this by adding output redirection to a tempfile for the command that is spawned.

rsp
Yes, stdout and stderr are being consumed. It's likely that the external script has not even started to run. We're seeing two instances of the primay java application which means forking has taken place but the exec part of the forkAndExec has not.
Mike