WAV を MP3 に順次変換するバッチ プロセスがあります。問題は、数千の後、開いたままのファイルが多すぎて、ファイルの制限に達してしまうことです。
これを行う理由は、SystemCommandTasklet のコードのためです。
FutureTask<Integer> systemCommandTask = new FutureTask<Integer>(new Callable<Integer>() {
public Integer call() throws Exception {
Process process = Runtime.getRuntime().exec(command, environmentParams, workingDirectory);
return process.waitFor();
}
});
これには、JVM に依存してプロセスをクリーンアップしたり、ファイルを開いたままにしたりするという厄介な副作用があります。
私はそれを次のように書き直しました:
FutureTask<Integer> systemCommandTask = new FutureTask<Integer>(new Callable<Integer>() {
public Integer call() throws Exception {
Process process = Runtime.getRuntime().exec(command, environmentParams, workingDirectory);
int status = process.waitFor();
process.getErrorStream().close();
process.getInputStream().close();
process.getOutputStream().flush();
process.getOutputStream().close();
process.destroy();
return status;
}
});
これが私の mac で動作することは 95% 確信していますが (lsof のおかげで)、どのシステムでも動作する適切なテストを作成して、実行しようとしていることが実際に動作していることを証明するにはどうすればよいでしょうか?