org.zeroturnaround.process

Class ProcessUtil

    • Constructor Detail

      • ProcessUtil

        public ProcessUtil()
    • Method Detail

      • waitFor

        public static void waitFor(SystemProcess process)
                            throws InterruptedException
        Waits until the given process finishes or the current thread is interrupted.
        Parameters:
        process - the target process.
        Throws:
        InterruptedException - if the current thread was interrupted.
      • waitFor

        public static void waitFor(SystemProcess process,
                   long timeout,
                   TimeUnit unit)
                            throws InterruptedException,
                                   TimeoutException
        Waits until the given process finishes, a timeout is reached or the current thread is interrupted.
        Parameters:
        process - the target process.
        timeout - the maximum time to wait until the process finishes.
        unit - the time unit of the timeout argument.
        Throws:
        InterruptedException - if the current thread was interrupted.
        TimeoutException - if timeout was reached before the process finished.
      • destroyGracefullyAndWait

        public static void destroyGracefullyAndWait(SystemProcess process,
                                    long timeout,
                                    TimeUnit unit)
                                             throws IOException,
                                                    InterruptedException,
                                                    TimeoutException
        Destroys the given process gracefully and waits until it finishes, a timeout occurs or the current thread is interrupted.
        Parameters:
        process - the target process.
        timeout - the maximum time to wait until the process finishes.
        unit - the time unit of the timeout argument.
        Throws:
        InterruptedException - if the current thread was interrupted.
        TimeoutException - if timeout was reached before the process finished.
        IOException
      • destroyForcefullyAndWait

        public static void destroyForcefullyAndWait(SystemProcess process,
                                    long timeout,
                                    TimeUnit unit)
                                             throws IOException,
                                                    InterruptedException,
                                                    TimeoutException
        Destroys the given process forcefully and waits until it finishes, a timeout occurs or the current thread is interrupted.
        Parameters:
        process - the target process.
        timeout - the maximum time to wait until the process finishes.
        unit - the time unit of the timeout argument.
        Throws:
        InterruptedException - if the current thread was interrupted.
        TimeoutException - if timeout was reached before the process finished.
        IOException
      • destroyGracefullyOrForcefullyAndWait

        public static void destroyGracefullyOrForcefullyAndWait(SystemProcess process)
                                                         throws IOException,
                                                                InterruptedException
        Destroys the given process gracefully and waits until it finishes or the current thread is interrupted. If the graceful destroy operation throws an exception (e.g. it's unsupported) it destroys the process forcefully and waits until it finishes or the current thread is interrupted.
        Parameters:
        process - the target process.
        Throws:
        InterruptedException - if the current thread was interrupted.
        IOException
      • destroyGracefullyOrForcefullyAndWait

        public static void destroyGracefullyOrForcefullyAndWait(SystemProcess process,
                                                long gracefulTimeout,
                                                TimeUnit gracefulTimeoutUnit)
                                                         throws IOException,
                                                                InterruptedException
        Destroys the given process gracefully and waits until it finishes, a timeout occurs or the current thread is interrupted. If the graceful destroy operation throws an exception (e.g. it's unsupported) or a timeout is reached it destroys the process forcefully and waits until it finishes or the current thread is interrupted (no timeout is used in this case).
        Parameters:
        process - the target process.
        timeout - the maximum time to wait until the process finishes after the graceful destroy operation.
        unit - the time unit of the timeout argument.
        Throws:
        InterruptedException - if the current thread was interrupted.
        IOException
      • destroyGracefullyOrForcefullyAndWait

        public static void destroyGracefullyOrForcefullyAndWait(SystemProcess process,
                                                long gracefulTimeout,
                                                TimeUnit gracefulTimeoutUnit,
                                                long forcefulTimeout,
                                                TimeUnit forcefulTimeoutUnit)
                                                         throws IOException,
                                                                InterruptedException,
                                                                TimeoutException
        Destroys the given process gracefully and waits until it finishes, first timeout occurs or the current thread is interrupted. If the graceful destroy operation throws an exception (e.g. it's unsupported) or a timeout is reached it destroys the process forcefully and waits until it finishes, second timeout occurs or the current thread is interrupted.
        Parameters:
        process - the target process.
        gracefulTimeout - the maximum time to wait until the process finishes after the graceful destroy operation.
        gracefulTimeoutUnit - the time unit of the gracefulTimeout argument.
        forcefulTimeout - the maximum time to wait until the process finishes after the forceful destroy operation.
        forcefulTimeoutUnit - the time unit of the forcefulTimeout argument.
        Throws:
        InterruptedException - if the current thread was interrupted.
        TimeoutException - if timeout was reached before the process finished (after the forceful destroy operation).
        IOException

Copyright © 2016 ZeroTurnaround. All rights reserved.