1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 32 public class TimedProcess 33 { 34 35 private Process process; 36 37 public TimedProcess(Process process) 38 { 39 this.process = process; 40 } 41 42 public int waitFor(int sec) 43 { 44 int exitValue = -1; 45 46 WaitForProcess t = new WaitForProcess(process); 48 t.start(); 49 50 try 52 { 53 t.join(sec * 1000); 54 55 if (t.isAlive()) 57 { 58 t.interrupt(); 59 60 System.err.println("Server Process did not complete in time. Destroying..."); 61 process.destroy(); 63 } 64 else 65 { 66 exitValue = t.getProcessExitValue(); 68 } 69 } 70 catch (InterruptedException e) 71 { 72 e.printStackTrace(); 73 } 74 75 return exitValue; 76 } 77 } 79 80 class WaitForProcess 81 extends Thread 82 { 83 private Process process; 84 private int processExitValue; 85 86 public WaitForProcess(Process process) 87 { 88 this.process = process; 89 } 90 91 public int getProcessExitValue() 92 { 93 return processExitValue; 94 } 95 96 public void run() 97 { 98 try 101 { 102 processExitValue = process.waitFor(); 103 } 104 catch (InterruptedException e) 105 { 106 } 108 } 109 } 111 | Popular Tags |