Hello all,
Let me say first that my experience with threading is pretty low.
I have an app that starts up several other Java jars via the Runtime.exec
method. The problem is that the jars that are started need to be run concurrently, but in order to get at the error stream for the started jars you have to basically have a loop 'sitting and listening' until the process completes.
This is what I have now:
_processes.add( Runtime.getRuntime().exec( commandList.toArray( new String[ commandList.size() ] ) ) );
Thread thread = new Thread( new Runnable() {
private final int _processNumber = _processes.size() - 1;
public void run() {
String streamData = _processNumber + " : ";
streamData += "StdError [\r";
BufferedReader bufferedReader =
new BufferedReader( new InputStreamReader( _processes.get( _processNumber ).getErrorStream() ) );
String line = null;
try {
while ( ( line = bufferedReader.readLine() ) != null ) {
streamData += line + "\r";
}
bufferedReader.close();
streamData += "]\r";
LOG.error( streamData );
}
catch ( Exception exception ) {
LOG.fatal( exception.getMessage() );
exception.printStackTrace();
}
}
} );
thread.start();
Can anyone explain how to get the 'error stream listener threads' to work properly?
TIA