forked from smallrye/smallrye-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes performance problem when creating log records or other things which frequently request the PID or process name. See quarkusio/quarkus#42858 for more info.
- Loading branch information
Showing
1 changed file
with
8 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,10 @@ | |
* @author <a href="mailto:[email protected]">David M. Lloyd</a> | ||
*/ | ||
public final class Process { | ||
private static final ProcessHandle current = doPrivileged((PrivilegedAction<ProcessHandle>) ProcessHandle::current); | ||
private static final ProcessHandle.Info currentInfo = current.info(); | ||
private static final String name = doPrivileged((PrivilegedAction<String>) Process::computeProcessName); | ||
|
||
private Process() { | ||
} | ||
|
||
|
@@ -39,14 +43,13 @@ private Process() { | |
* @return the process name (not {@code null}) | ||
*/ | ||
public static String getProcessName() { | ||
return doPrivileged((PrivilegedAction<String>) Process::computeProcessName); | ||
return name; | ||
} | ||
|
||
private static String computeProcessName() { | ||
final ProcessHandle processHandle = ProcessHandle.current(); | ||
String processName = System.getProperty("jboss.process.name"); | ||
if (processName == null) { | ||
processName = processHandle.info().command().orElse(null); | ||
processName = currentInfo.command().orElse(null); | ||
} | ||
if (processName == null) { | ||
processName = "<unknown>"; | ||
|
@@ -62,7 +65,7 @@ private static String computeProcessName() { | |
*/ | ||
@Deprecated(since = "2.4", forRemoval = true) | ||
public static long getProcessId() { | ||
return currentProcess().pid(); | ||
return current.pid(); | ||
} | ||
|
||
/** | ||
|
@@ -73,12 +76,7 @@ public static long getProcessId() { | |
*/ | ||
@Deprecated(since = "2.4", forRemoval = true) | ||
public static ProcessInfo getCurrentProcess() { | ||
return new ProcessInfo(currentProcess().pid(), getProcessName()); | ||
} | ||
|
||
// do not make this public | ||
private static ProcessHandle currentProcess() { | ||
return doPrivileged((PrivilegedAction<ProcessHandle>) ProcessHandle::current); | ||
return new ProcessInfo(current.pid(), getProcessName()); | ||
} | ||
|
||
/** | ||
|