运行其他命令时,Java Runtime.exec的运行速度越来越慢。
我将“Runtime.getRuntime()。exec”定时约三天,这个函数花费的时间越来越多,从0/1 ms到500+ ms。所以......
但是当我在shell脚本中运行“ipmitool raw 0x3e 0x31 3 1”时,通常会花费时间。
所以谁知道这个问题的原因是什么?感谢。
这是代码:
String shStr="ipmitool raw 0x3e 0x31 3 1";
public static List<String> runShell(String shStr) throws Exception {
List<String> strList = new ArrayList<String>();
long start_time = System.currentTimeMillis();
Process process;
process = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c",shStr},null,null);
long time1 = System.currentTimeMillis();
System.out.println("runShell exec time cost" + (time1 - start_time));
InputStreamReader ir = new InputStreamReader(process
.getInputStream());
InputStreamReader stderrReader = new
InputStreamReader(process.getErrorStream());
LineNumberReader input = new LineNumberReader(ir);
LineNumberReader errInput = new LineNumberReader(stderrReader);
String line;
process.waitFor();
while ((line = input.readLine()) != null) {
strList.add(line);
}
System.out.println("ERROR");
while ((line = errInput.readLine()) != null) {
System.out.println(line);
}
return strList;
}