wait for Process

来源:互联网 发布:淘宝网购 编辑:程序博客网 时间:2024/04/30 14:54

如果仅仅是用process.waitFor()的话,如果进程挂起这个将永远得不到返回值,是用捕捉getExitValue异常的办法可以work around

 private int myWaitProcessFinish(Process process) throws InterruptedException{
  boolean finish = false;
  int exitValue = -1;
  int timeout = 0;
  while(!finish && 60 < timeout++){
   try{
    exitValue = process.exitValue();
    finish = true;
   } catch(Exception e) {
    Thread.sleep(500);    
   }
  }
  return exitValue;
 }

原创粉丝点击