jdk/test/java/rmi/testlibrary/JavaVM.java
changeset 22990 daa64fcb5ba7
parent 22091 9e1731e5cfc7
child 23064 e16d4c844e76
equal deleted inserted replaced
22989:2d6804cfdc0e 22990:daa64fcb5ba7
    24 import java.io.File;
    24 import java.io.File;
    25 import java.io.IOException;
    25 import java.io.IOException;
    26 import java.io.OutputStream;
    26 import java.io.OutputStream;
    27 import java.util.Arrays;
    27 import java.util.Arrays;
    28 import java.util.StringTokenizer;
    28 import java.util.StringTokenizer;
       
    29 import java.util.concurrent.TimeoutException;
    29 
    30 
    30 /**
    31 /**
    31  * RMI regression test utility class that uses Runtime.exec to spawn a
    32  * RMI regression test utility class that uses Runtime.exec to spawn a
    32  * java process that will run a named java class.
    33  * java process that will run a named java class.
    33  */
    34  */
   171         errPipe.join();
   172         errPipe.join();
   172         return status;
   173         return status;
   173     }
   174     }
   174 
   175 
   175     /**
   176     /**
       
   177      * Causes the current thread to wait the vm process to exit, if necessary,
       
   178      * wait until the vm process has terminated, or the specified waiting time
       
   179      * elapses. Release allocated input/output after vm process has terminated.
       
   180      * @param timeout the maximum milliseconds to wait.
       
   181      * @return exit value for vm process.
       
   182      * @throws InterruptedException if the current thread is interrupted
       
   183      *         while waiting.
       
   184      * @throws TimeoutException if subprocess does not end after timeout
       
   185      *         milliseconds passed
       
   186      */
       
   187     public int waitFor(long timeout)
       
   188             throws InterruptedException, TimeoutException {
       
   189         if (vm == null)
       
   190             throw new IllegalStateException("can't wait for JavaVM that isn't running");
       
   191         long startTime = System.currentTimeMillis();
       
   192         long rem = timeout;
       
   193 
       
   194         do {
       
   195             try {
       
   196                 int status = vm.exitValue();
       
   197                 outPipe.join();
       
   198                 errPipe.join();
       
   199                 return status;
       
   200             } catch (IllegalThreadStateException ex) {
       
   201                 if (rem > 0) {
       
   202                     Thread.sleep(Math.min(rem, 100));
       
   203                 }
       
   204             }
       
   205             rem = timeout - (System.currentTimeMillis() - startTime);
       
   206         } while (rem > 0);
       
   207         throw new TimeoutException();
       
   208     }
       
   209 
       
   210     /**
   176      * Starts the subprocess, waits for it to exit, and returns its exit status.
   211      * Starts the subprocess, waits for it to exit, and returns its exit status.
   177      */
   212      */
   178     public int execute() throws IOException, InterruptedException {
   213     public int execute() throws IOException, InterruptedException {
   179         start();
   214         start();
   180         return waitFor();
   215         return waitFor();