jdk/test/java/rmi/testlibrary/JavaVM.java
changeset 27931 9089cd529a79
parent 23064 e16d4c844e76
child 27943 4ed49775c237
--- a/jdk/test/java/rmi/testlibrary/JavaVM.java	Wed Jul 05 20:10:08 2017 +0200
+++ b/jdk/test/java/rmi/testlibrary/JavaVM.java	Thu Dec 04 18:54:37 2014 -0800
@@ -34,6 +34,8 @@
  */
 public class JavaVM {
 
+    public static final long POLLTIME_MS = 100L;
+
     protected Process vm = null;
 
     private String classname = "";
@@ -192,23 +194,21 @@
             throws InterruptedException, TimeoutException {
         if (vm == null)
             throw new IllegalStateException("can't wait for JavaVM that isn't running");
-        long startTime = System.currentTimeMillis();
-        long rem = timeout;
+        long deadline = System.currentTimeMillis() + timeout;
 
-        do {
+        while (true) {
             try {
                 int status = vm.exitValue();
                 outPipe.join();
                 errPipe.join();
                 return status;
-            } catch (IllegalThreadStateException ex) {
-                if (rem > 0) {
-                    Thread.sleep(Math.min(rem, 100));
-                }
-            }
-            rem = timeout - (System.currentTimeMillis() - startTime);
-        } while (rem > 0);
-        throw new TimeoutException();
+            } catch (IllegalThreadStateException ignore) { }
+
+            if (System.currentTimeMillis() > deadline)
+                throw new TimeoutException();
+
+            Thread.sleep(POLLTIME_MS);
+        }
     }
 
     /**