Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8056049

getProcessCpuLoad() stops working in one process when a different process exits

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8u20, 9
    • Fix Version/s: 8u40
    • Component/s: core-svc
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b16
    • CPU:
      x86
    • OS:
      windows_7
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_20"
        Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
        Java HotSpot(TM) Client VM (build 25.20-b23, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Gradle 1.11

        A DESCRIPTION OF THE PROBLEM :
        This bug sounds crazy, but it is 100% reproducible on multiple machines. If the gradle daemon is running *before* I start a separate java process which uses com.sun.management.OperatingSystemMXBean.getProcessCpuLoad() then the method will return the correct CPU load only while the gradle daemon is still running. Once the gradle daemon is stopped, getProcessCpuLoad() always returns -1. If the gradle daemon is started back up, getProcessCpuLoad() starts working again.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Download gradle 1.11 and add the bin directory to the path
        2. In a command window, run gradle --daemon
        3. In a separate window, execute the java app listed below
        4. The app will begin outputting the current CPU load a few times per second. Initialli, it prints CPU: -1.000000, but quickly begins the correct value (i.e. CPU: 0.000000).
        5. In the first command window, run gradle --daemon --stop
        6. Verify that as soon as the gradle daemon stops, the test app reverts back to CPU: -1.000000.
        7. Start the gradle daemon again using gradle --daemon
        8. Verify that as soon as the gradle process starts, the test app begins producing real CPU load values.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        In step 6 above, getProcessCpuLoad() should return the correct CPU load
        ACTUAL -
        In step 6 above, getProcessCpuLoad() returns -1 instead of the current process CPU load.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import com.sun.management.OperatingSystemMXBean;

        import java.lang.management.ManagementFactory;

        public class TestApp
        {
            private static final OperatingSystemMXBean mxBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);

            private static double getProcessCpuLoad()
            {
                return mxBean.getProcessCpuLoad();
            }

            public static void main(String[] args) throws Exception
            {
                while (true)
                {
                    System.out.printf("CPU: %f%n", getProcessCpuLoad());
                    Thread.sleep(100);
                }
            }
        }

        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                mgronlun Markus Grönlund
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: