大きなデータを返す (完了するまでに 2 時間以上かかる) 外部アプリケーションを実行する必要があり、データを継続的に出力します。
私がする必要があるのは、このプログラムを非同期で実行し、出力をファイルにキャプチャすることです。Javaプロセスビルダーを使用してみましたが、プログラムが終了または強制終了された場合にのみハングして出力を返すようです。
プロセスビルダーを使用して、新しいスレッドを作成して出力をキャプチャしようとしましたが、それでも役に立ちませんでした。
次に、apache commons exec について読み、同じことを試しました。ただし、これにも時間がかかるようで、異なるエラーコードを返します(同じ入力に対して)
CommandLine cmdLine = new CommandLine("/opt/testsimulator");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
PumpStreamHandler psh = new PumpStreamHandler(stdout);
ExecuteWatchdog watchdog = new ExecuteWatchdog(60*1000);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(psh);
executor.setWatchdog(watchdog);
try {
executor.execute(cmdLine);
} catch (ExecuteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
非常に役立つヘルプまたは実際の例