Java TimeUnit Usage waitForProcess(Process process, String name)

Here you can find the source of waitForProcess(Process process, String name)

Description

wait For Process

License

Apache License

Declaration

public static int waitForProcess(Process process, String name) throws RuntimeException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.concurrent.TimeUnit;

public class Main {
    private static final int KILL_TIMEOUT = 20000;

    public static int waitForProcess(Process process, String name) throws RuntimeException {
        return waitForProcess(process, name, true);
    }/*from   w  w  w  .j  a va 2 s.  c o  m*/

    public static int waitForProcess(Process process, String name, boolean throwError) throws RuntimeException {
        boolean finished = false;
        try {
            finished = process.waitFor(KILL_TIMEOUT, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            /* do nothing */}
        if (!finished) {
            throw new RuntimeException(name + " subprocess terminated.");
        } else if (process.exitValue() != 0) {
            if (throwError) {
                throw new RuntimeException(name + " subprocess failed: " + process.exitValue());
            }
        }
        return process.exitValue();
    }
}

Related

  1. unixToJavaTime(long utime)
  2. waitFor(long period)
  3. waitFor(Object obj)
  4. waitFor(Semaphore semaphore, long timeoutInMillis)
  5. waitForMinutes(long time)
  6. waitForResponseObject(BlockingQueue queue, Class clazz)
  7. waitForSignal(CountDownLatch b)
  8. weekendMinutesBetween(Date date1, Date date2)
  9. zeroOutMs(long timestamp)

  10. HOME | Copyright © www.java2s.com 2016