public class ProcessUtil
extends java.lang.Object
| Constructor and Description |
|---|
ProcessUtil(java.util.logging.Logger logger) |
| Modifier and Type | Method and Description |
|---|---|
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getJavaPIDs()
Gets a map with key=(running java main classes) and value=(list of the process IDs).
|
java.util.List<java.lang.String> |
getJavaPIDs(java.lang.Class<?> mainClass)
Gets the process IDs of all java processes run by the current user on the local host,
whose main class is given as the parameter.
|
boolean |
isJavaProcessRunning(java.lang.Class<?> mainClass)
Returns true if one or more JVMs are running the given Java main class
on the local host as the current user.
|
int |
killProcess(java.lang.String pid,
boolean tough)
Kills a process with a given PID, which could be obtained from
getJavaPIDs(Class). |
void |
setDebug(boolean DEBUG) |
public java.util.List<java.lang.String> getJavaPIDs(java.lang.Class<?> mainClass)
throws java.io.IOException
The "jps" command is used via Runtime.exec, which should work not only on Linux but also on Windows.
java.io.IOExceptionpublic boolean isJavaProcessRunning(java.lang.Class<?> mainClass)
throws java.io.IOException
java.io.IOExceptionpublic int killProcess(java.lang.String pid,
boolean tough)
throws java.io.IOException,
java.lang.InterruptedException
getJavaPIDs(Class).
tough - if true, a tough way of killing is used (kill -9)java.io.IOExceptionjava.lang.InterruptedExceptionprotected java.util.Map<java.lang.String,java.util.List<java.lang.String>> getJavaPIDs()
throws java.io.IOException
java.io.IOExceptionjava.lang.InterruptedExceptionpublic void setDebug(boolean DEBUG)