You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2013/08/27 22:06:48 UTC

svn commit: r1517964 - /jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java

Author: sebb
Date: Tue Aug 27 20:06:47 2013
New Revision: 1517964

URL: http://svn.apache.org/r1517964
Log:
Simplify and avoid calling exitValue() twice if the process has ended.

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java?rev=1517964&r1=1517963&r2=1517964&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java Tue Aug 27 20:06:47 2013
@@ -157,33 +157,23 @@ public class SystemCommand {
         } else {
             long now = System.currentTimeMillis();
             long finish = now + timeoutInMillis;
-            while (isAlive(proc) && (System.currentTimeMillis() < finish)) {
-                Thread.sleep(pollInterval);
+            while(System.currentTimeMillis() < finish) {
+                try {
+                    return proc.exitValue();
+                } catch (IllegalThreadStateException e) { // not yet terminated
+                    Thread.sleep(pollInterval);
+                }
             }
-            
-            if (isAlive(proc)) {
+            try {
+                return proc.exitValue();
+            } catch (IllegalThreadStateException e) { // not yet terminated
                 // N.B. proc.destroy() is called by the finally clause in the run() method
                 throw new InterruptedException( "Process timeout out after " + timeoutInMillis + " milliseconds" );
             }
-            return proc.exitValue();
         }
     }
 
     /**
-     * Check if the process is still running.
-     * @param p Process
-     * @return true if p is still running
-     */
-    private static boolean isAlive(Process p) {
-        try {
-            p.exitValue();
-            return false;
-        } catch (IllegalThreadStateException e) {
-            return true;
-        }
-    }
-    
-    /**
      * @return Out/Err stream contents
      */
     public String getOutResult() {