我这边有一个程序,之前在windows下执行没有任何问题,今日放到linux系统服务器上跑,以下程序总是超时,我感觉肯定和操作系统有关系,希望有经验的大牛指导一下,共勉,谢谢:public static void main(String[] args) {
try {
long fromDate = System.currentTimeMillis();
Process process = Runtime.getRuntime().exec("java gx.RegistClient");
long thruDate = System.currentTimeMillis();
boolean finish = false;
while ((thruDate - fromDate < 120000) && !finish) {
try {
int ret = process.exitValue();
System.out.println("exec cmd result process: " + ret);//这里总是反回 1,我觉得和操作系统控制进程有关?
if (ret == 0) finish = true;
} catch (Exception e) {
System.err.println("exec cmd err: " + e.getMessage());
}
Thread.sleep(500);
thruDate = System.currentTimeMillis();
}
System.out.println("========================总是时间超时,即thruDate - fromDate >120000 跳出while===========================>");
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
try {
long fromDate = System.currentTimeMillis();
Process process = Runtime.getRuntime().exec("java gx.RegistClient");
long thruDate = System.currentTimeMillis();
boolean finish = false;
while ((thruDate - fromDate < 120000) && !finish) {
try {
int ret = process.exitValue();
System.out.println("exec cmd result process: " + ret);//这里总是反回 1,我觉得和操作系统控制进程有关?
if (ret == 0) finish = true;
} catch (Exception e) {
System.err.println("exec cmd err: " + e.getMessage());
}
Thread.sleep(500);
thruDate = System.currentTimeMillis();
}
System.out.println("========================总是时间超时,即thruDate - fromDate >120000 跳出while===========================>");
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
不是,我是调用另外一个配置在classpath下的插件jar,他会做一些事情,通过io返回给我字符数据。
在windows可行。至于您说的这个调用,会产生什么大的影响?process.exitValue();一直返回1,和这个有关系吧?
是这个道理,但是我们这个项目吧,有点特殊,这个jar或者说功能就是给一个地方做的,不太想牵扯到产品代码本身,所以就用了这种方式。
之前的问题已经解决了,是由于AIX系统的classpath有问题(可是aix命令行没问题),我加上-cp直接指定了。
谢谢指点,结贴了