学习同事的一段代码。。。
Runtime run = Runtime.getRuntime();
final Process p = run.exec(command);
ExecutorService pool = Executors.newFixedThreadPool(1);
Future<Integer> future = pool.submit(new Callable<Integer>() {
public Integer call() {
try {
return p.waitFor();
} catch (InterruptedException e) {
}
return 1;
}
});
int result = 1;
String error = "unknow";
try {
result = future.get(20l,TimeUnit.SECONDS);
} catch (InterruptedException e) {
error = e.toString();
} catch (ExecutionException e) {
error = e.toString();
} catch (TimeoutException e) {
error = e.toString();
}
663

被折叠的 条评论
为什么被折叠?



