【发布时间】:2011-12-05 10:35:39
【问题描述】:
我在使用 Java ProcessBuilder 时遇到了一个奇怪的问题。代码如下所示(稍微简化)
public class Whatever implements Runnable
{
public void run(){
//someIdentifier is a randomly generated string
String in = someIdentifier + "input.txt";
String out = someIdentifier + "output.txt";
ProcessBuilder builder = new ProcessBuilder("./whateveer.sh", in, out);
try {
Process process = builder.start();
process.waitFor();
} catch (IOException e) {
log.error("Could not launch process. Command: " + builder.command(), e);
} catch (InterruptedException ex) {
log.error(ex);
}
}
}
无论.sh 读什么:
R --slave --args $1 $2 <whatever1.R >> r.log
Whatever 的实例负载被提交到固定大小 (35) 的 ExecutorService。应用程序的其余部分等待它们全部完成——使用CountdownLatch 实现。在抛出以下异常之前,一切运行良好(Scientific Linux 5.0,java 版本“1.6.0_24”):
java.io.IOException: Cannot run program "./whatever.sh": java.io.IOException: error=11, Resource temporarily unavailable
at java.lang.ProcessBuilder.start(Unknown Source)
... rest of stack trace omitted...
有人知道这意味着什么吗?根据java.io.IOException: error=11 的 google/bing 搜索结果,这不是最常见的异常,我完全感到困惑。
我的狂野和不那么有根据的猜测是,我有太多线程试图同时启动同一个文件。但是,重现该问题需要数小时的 CPU 时间,因此我没有尝试使用较小的数字。
非常感谢任何建议。
【问题讨论】:
-
你用
lsof检查过你的java进程的打开文件数吗? -
是 errno 11 还是 12 还是两者都有?
标签: java linux process processbuilder