Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 10
    • Component/s: core-svc
    • Labels:
      None
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      New API
    • Interface Kind:
      Java API
    • Scope:
      SE

      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

            Activity

              People

              • Assignee:
                uvangapally Ujwal Vangapally (Inactive)
                Reporter:
                hirt Marcus Hirt
                Reviewed By:
                Mandy Chung
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: