public class ProcessUtil extends Object
Here all methods that use a timeout throw TimeoutException including the given timeout in the message
instead of returning a false like SystemProcess does.
Also all methods log a message in case the operation succeeded including the time it took.
Notice that methods that destroy a process do not include destroying operation itself in the timeout period. They start measuring time after sending the destroy signal. Also if the current thread is interrupted it may also interrupt sending the destroy signal itself not just the waiting period after it. So if the current thread gets interrupted there's no guarantee that the target process actually got signaled.
SystemProcess| Constructor and Description |
|---|
ProcessUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
destroyForcefullyAndWait(SystemProcess process)
Destroys the given process forcefully and waits until it finishes or the current thread is interrupted.
|
static void |
destroyForcefullyAndWait(SystemProcess process,
long timeout,
TimeUnit unit)
Destroys the given process forcefully and waits until it finishes, a timeout occurs or the current thread is interrupted.
|
static void |
destroyGracefullyAndWait(SystemProcess process)
Destroys the given process gracefully and waits until it finishes or the current thread is interrupted.
|
static void |
destroyGracefullyAndWait(SystemProcess process,
long timeout,
TimeUnit unit)
Destroys the given process gracefully and waits until it finishes, a timeout occurs or the current thread is interrupted.
|
static void |
destroyGracefullyOrForcefullyAndWait(SystemProcess process)
Destroys the given process gracefully and waits until it finishes or the current thread is interrupted.
|
static void |
destroyGracefullyOrForcefullyAndWait(SystemProcess process,
long gracefulTimeout,
TimeUnit gracefulTimeoutUnit)
Destroys the given process gracefully and waits until it finishes, a timeout occurs or the current thread is interrupted.
|
static void |
destroyGracefullyOrForcefullyAndWait(SystemProcess process,
long gracefulTimeout,
TimeUnit gracefulTimeoutUnit,
long forcefulTimeout,
TimeUnit forcefulTimeoutUnit)
Destroys the given process gracefully and waits until it finishes, first timeout occurs or the current thread is interrupted.
|
static void |
waitFor(SystemProcess process)
Waits until the given process finishes or the current thread is interrupted.
|
static void |
waitFor(SystemProcess process,
long timeout,
TimeUnit unit)
Waits until the given process finishes, a timeout is reached or the current thread is interrupted.
|
public static void waitFor(SystemProcess process) throws InterruptedException
process - the target process.InterruptedException - if the current thread was interrupted.public static void waitFor(SystemProcess process, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException
process - the target process.timeout - the maximum time to wait until the process finishes.unit - the time unit of the timeout argument.InterruptedException - if the current thread was interrupted.TimeoutException - if timeout was reached before the process finished.public static void destroyGracefullyAndWait(SystemProcess process) throws IOException, InterruptedException
process - the target process.IOException - on IO error.InterruptedException - if the current thread was interrupted.public static void destroyGracefullyAndWait(SystemProcess process, long timeout, TimeUnit unit) throws IOException, InterruptedException, TimeoutException
process - the target process.timeout - the maximum time to wait until the process finishes.unit - the time unit of the timeout argument.IOException - on IO error.InterruptedException - if the current thread was interrupted.TimeoutException - if timeout was reached before the process finished.public static void destroyForcefullyAndWait(SystemProcess process) throws IOException, InterruptedException
process - the target process.IOException - on IO error.InterruptedException - if the current thread was interrupted.public static void destroyForcefullyAndWait(SystemProcess process, long timeout, TimeUnit unit) throws IOException, InterruptedException, TimeoutException
process - the target process.timeout - the maximum time to wait until the process finishes.unit - the time unit of the timeout argument.IOException - on IO error.InterruptedException - if the current thread was interrupted.TimeoutException - if timeout was reached before the process finished.public static void destroyGracefullyOrForcefullyAndWait(SystemProcess process) throws IOException, InterruptedException
process - the target process.IOException - on IO error.InterruptedException - if the current thread was interrupted.public static void destroyGracefullyOrForcefullyAndWait(SystemProcess process, long gracefulTimeout, TimeUnit gracefulTimeoutUnit) throws IOException, InterruptedException
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 timeout argument.IOException - on IO error.InterruptedException - if the current thread was interrupted.public static void destroyGracefullyOrForcefullyAndWait(SystemProcess process, long gracefulTimeout, TimeUnit gracefulTimeoutUnit, long forcefulTimeout, TimeUnit forcefulTimeoutUnit) throws IOException, InterruptedException, TimeoutException
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.IOException - on IO error.InterruptedException - if the current thread was interrupted.TimeoutException - if timeout was reached before the process finished (after the forceful destroy operation).Copyright © 2019 ZeroTurnaround. All rights reserved.