Package org.zeroturnaround.process
Class Java8Process
java.lang.Object
org.zeroturnaround.process.AbstractProcess
org.zeroturnaround.process.JavaProcess
org.zeroturnaround.process.Java8Process
- All Implemented Interfaces:
SystemProcess
Wrapper for
Process since Java 8.
Java 8 added following methods:
isAlive()destroyForcibly()waitFor(long, TimeUnit)
-
Field Summary
Fields inherited from class org.zeroturnaround.process.JavaProcess
process -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanDestroy(boolean forceful) Check if destroying the process is supported based on the OS and JVM version (regardless the process is running or not).protected voidinvokeDestroy(boolean forceful) booleanisAlive()Tests whether this process is alive.static booleanbooleanCauses the current thread to wait, if necessary, until the process handled by this killer has terminated, or the specified timeout is reached.Methods inherited from class org.zeroturnaround.process.JavaProcess
destroy, getDescription, getProcess, waitForMethods inherited from class org.zeroturnaround.process.AbstractProcess
destroyForcefully, destroyGracefully, toString
-
Constructor Details
-
Java8Process
-
-
Method Details
-
isSupported
public static boolean isSupported() -
canDestroy
protected boolean canDestroy(boolean forceful) Description copied from class:JavaProcessCheck if destroying the process is supported based on the OS and JVM version (regardless the process is running or not).- Overrides:
canDestroyin classJavaProcess- Parameters:
forceful-trueif the process must be destroyed forcefully (likekill -KILL),falseif it must be destroyed gracefully (likekill -TERM).- Returns:
trueifJavaProcess.invokeDestroy(boolean)is supported with the givenforcefulflag on the given system.
-
invokeDestroy
protected void invokeDestroy(boolean forceful) - Overrides:
invokeDestroyin classJavaProcess
-
invokeDestroyForcibly
-
isAlive
public boolean isAlive()Description copied from interface:SystemProcessTests whether this process is alive.This operation may take some time to finish.
- Specified by:
isAlivein interfaceSystemProcess- Overrides:
isAlivein classJavaProcess- Returns:
trueif this process is alive,falseif it is finished or not found.
-
waitFor
Description copied from class:AbstractProcessCauses the current thread to wait, if necessary, until the process handled by this killer has terminated, or the specified timeout is reached.If the process has already terminated then this method returns immediately with the value
true. If the process has not terminated and the timeout value is less than, or equal to, zero, then this method returns immediately with the valuefalse.- Specified by:
waitForin interfaceSystemProcess- Overrides:
waitForin classAbstractProcess- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
trueif the process has exited andfalseif the timeout is reached before the process has exited.- Throws:
InterruptedException- if interrupted.
-