-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also simplify the computation of process name, and deprecate these methods in favor of the far superior `ProcessHandle` API.
- Loading branch information
Showing
4 changed files
with
19 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,49 +28,49 @@ | |
* @author <a href="mailto:[email protected]">David M. Lloyd</a> | ||
*/ | ||
public final class Process { | ||
private static final ProcessInfo currentProcess; | ||
|
||
static { | ||
currentProcess = doPrivileged(new GetProcessInfoAction()); | ||
} | ||
|
||
private Process() { | ||
} | ||
|
||
/** | ||
* Get the name of this process. If the process name is not known, then "<unknown>" is returned. | ||
* The process name may be overridden by setting the {@code jboss.process.name} property. | ||
* | ||
* @return the process name (not {@code null}) | ||
*/ | ||
public static String getProcessName() { | ||
return currentProcess.getCommand(); | ||
return doPrivileged(new GetProcessInfoAction()).getCommand(); | ||
} | ||
|
||
/** | ||
* Get the ID of this process. This is the operating system specific PID. If the PID cannot be determined, | ||
* -1 is returned. | ||
* Get the ID of this process. This is the operating system specific PID. | ||
* | ||
* @return the ID of this process, or -1 if it cannot be determined | ||
* @return the ID of this process | ||
* @deprecated Use {@link ProcessHandle#pid()} instead. | ||
*/ | ||
@Deprecated | ||
public static long getProcessId() { | ||
return currentProcess.getId(); | ||
return ProcessHandle.current().pid(); | ||
} | ||
|
||
/** | ||
* Returns information about the current process | ||
* | ||
* @return the current process | ||
* @deprecated Use {@link ProcessHandle#current()} to get the current process information. | ||
*/ | ||
@Deprecated | ||
public static ProcessInfo getCurrentProcess() { | ||
return currentProcess; | ||
return new ProcessInfo(ProcessHandle.current().pid(), getProcessName()); | ||
} | ||
|
||
/** | ||
* Returns all the running processes. | ||
* | ||
* @return a list of all the running processes. May throw an exception if running on an unsupported JDK | ||
* @throws UnsupportedOperationException if running on JDK 8 | ||
* @deprecated Use {@link ProcessHandle#allProcesses()} instead. | ||
*/ | ||
@Deprecated | ||
public static List<ProcessInfo> getAllProcesses() { | ||
return doPrivileged(new GetAllProcessesInfoAction()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters