Package org.zeroturnaround.process
Class JavaProcess
java.lang.Object
org.zeroturnaround.process.AbstractProcess
org.zeroturnaround.process.JavaProcess
- All Implemented Interfaces:
SystemProcess
- Direct Known Subclasses:
Java8Process
Wrapper for
Process.-
Field Summary
FieldsFields inherited from class org.zeroturnaround.process.AbstractProcess
log -
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).voiddestroy(boolean forceful) Destroys the process either forcefully or gracefully according to the given option.Returns the wrapped process.protected voidinvokeDestroy(boolean forceful) booleanisAlive()Tests whether this process is alive.voidwaitFor()Causes the current thread to wait, if necessary, until this process has terminated.Methods inherited from class org.zeroturnaround.process.AbstractProcess
destroyForcefully, destroyGracefully, toString, waitFor
-
Field Details
-
process
The wrapped process.
-
-
Constructor Details
-
JavaProcess
-
-
Method Details
-
getProcess
Returns the wrapped process.- Returns:
- the wrapped process.
-
getDescription
- Specified by:
getDescriptionin classAbstractProcess- Returns:
- the description of the system process.
-
isAlive
public boolean isAlive()Description copied from interface:SystemProcessTests whether this process is alive.This operation may take some time to finish.
- Returns:
trueif this process is alive,falseif it is finished or not found.
-
waitFor
Description copied from interface:SystemProcessCauses the current thread to wait, if necessary, until this process has terminated.This method returns immediately if the process has already terminated. If the process has not yet terminated, the calling thread will be blocked until the process exits.
- Throws:
InterruptedException- if interrupted.
-
destroy
Description copied from class:AbstractProcessDestroys the process either forcefully or gracefully according to the given option.Note: The process may not terminate at all. i.e.
isAlive()may returntruefor a any period afterdestroy()is called. This method may be chained towaitFor()if needed.No error is thrown if the process was already terminated.
- Specified by:
destroyin classAbstractProcess- Parameters:
forceful-trueif the process must be destroyed forcefully (likekill -KILL),falseif it must be destroyed gracefully (likekill -TERM).- Throws:
IOException- on IO error.
-
canDestroy
protected boolean canDestroy(boolean forceful) Check if destroying the process is supported based on the OS and JVM version (regardless the process is running or not).- Parameters:
forceful-trueif the process must be destroyed forcefully (likekill -KILL),falseif it must be destroyed gracefully (likekill -TERM).- Returns:
trueifinvokeDestroy(boolean)is supported with the givenforcefulflag on the given system.
-
invokeDestroy
protected void invokeDestroy(boolean forceful)
-