mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 20:14:43 +02:00
8073132: Eliminate ProcessTools.getProcessId dependency on sun.management.VMManagement
Reviewed-by: jbachorik, dfuchs, mchung
This commit is contained in:
parent
0d2c28e3b8
commit
3d3f6553c0
1 changed files with 1 additions and 14 deletions
|
@ -33,8 +33,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import sun.management.VMManagement;
|
||||
|
||||
public final class ProcessTools {
|
||||
|
||||
private ProcessTools() {
|
||||
|
@ -90,19 +88,8 @@ public final class ProcessTools {
|
|||
* @return Process id
|
||||
*/
|
||||
public static int getProcessId() throws Exception {
|
||||
|
||||
// Get the current process id using a reflection hack
|
||||
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
|
||||
Field jvm = runtime.getClass().getDeclaredField("jvm");
|
||||
|
||||
jvm.setAccessible(true);
|
||||
VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
|
||||
|
||||
Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
|
||||
|
||||
pid_method.setAccessible(true);
|
||||
|
||||
int pid = (Integer) pid_method.invoke(mgmt);
|
||||
int pid = Integer.parseInt(runtime.getName().split("@")[0]);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue