在我的JSF2.0网站中,我一次在后台一个线程中调用一些shell脚本。我需要等到所有这些程序都成功调用。以下是代码的片段 -
ExecutorService taskExecutor = Executors.newSingleThreadExecutor();
for (String script : scriptList){
taskExecutor.execute(new Runnable() {
@Override
public void run() {
try {
log.info("Trying to start script " +script);
startScript(program);
} catch (Exception ex) {
log.error("Exception ." + ex.getMessage());
}
}
});
}
taskExecutor.shutdown();
try {
taskExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
log.error("InterruptedException ." + e.getMessage());
}
// Now I can proceed further can call other methods
我从上面的代码运行的shell脚本在运行时显示stdout
。我想逐个调用后台脚本而不捕获他们的stdout
。我不想等到他们完成。只调用信号。