Details
Description
Summary
Introduced new API java.lang.management.RuntimeMXBean.getPid
to get process ID of running Java virtual machine.
Problem
The platform MBean does not provide any API to get the process ID of a running JVM. Some JMX tools rely on the hotspot implementation of RuntimeMXBean::getName
which returns < pid >@< hostname >.
Solution
Introduced new API java.lang.management.RuntimeMXBean.getPid
, so that JMX tools can directly get process ID instead of relying on the implementation detail, RuntimeMXBean#getName().split("@")[0]
.
Specification
--- old/src/java.management/share/classes/java/lang/management/RuntimeMXBean.java 2017-11-02 15:03:57.177210581 +0530
+++ new/src/java.management/share/classes/java/lang/management/RuntimeMXBean.java 2017-11-02 15:03:56.993210581 +0530
@@ -25,6 +25,9 @@
package java.lang.management;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
/**
* The management interface for the runtime system of
* the Java virtual machine.
@@ -61,6 +64,22 @@
*/
public interface RuntimeMXBean extends PlatformManagedObject {
/**
+ * Returns the {@linkplain ProcessHandle#pid process ID} representing
+ * the running Java virtual machine.
+ *
+ * @implSpec The default implementation returns {@link ProcessHandle#pid process ID}
+ * of the {@linkplain ProcessHandle#current current process}.
+ *
+ * @return the process ID representing the running Java virtual machine.
+ *
+ * @since 10
+ */
+ public default long getPid() {
+ return AccessController.doPrivileged((PrivilegedAction<Long>)
+ () -> ProcessHandle.current().pid());
+ }
+
+ /**
* Returns the name representing the running Java virtual machine.
* The returned name string can be any arbitrary string and
* a Java virtual machine implementation can choose
Attachments
Issue Links
- csr of
-
JDK-8044122 MBean access to the PID
-
- Resolved
-
- relates to
-
JDK-8176314 JMX: RuntimeMXBean support for monitoring modular runtime information
-
- Open
-