< prev index next >

test/lib/testlibrary/jdk/testlibrary/ProcessTools.java

Print this page

        

@@ -25,12 +25,10 @@
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
-import java.lang.management.ManagementFactory;
-import java.lang.management.RuntimeMXBean;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;

@@ -251,15 +249,12 @@
     /**
      * Get the process id of the current running Java process
      *
      * @return Process id
      */
-    public static int getProcessId() throws Exception {
-        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
-        int pid = Integer.parseInt(runtime.getName().split("@")[0]);
-
-        return pid;
+    public static int getProcessId() {
+        return (int) ProcessHandle.current().getPid();
     }
 
     /**
      * Get platform specific VM arguments (e.g. -d64 on 64bit Solaris)
      *
< prev index next >