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

sun.jvmstat.monitor.MonitoredHost.getMonitoredHost() throws unexpected exceptions when invoked concurrently

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 22
    • 17, 21, 22
    • core-svc
    • b27

    Description

      When multiple threads concurrently invoke on sun.jvmstat.monitor.MonitoredHost.getMonitoredHost() method, it has been noticed that it sometimes throws unexpected exceptions like:

      On one occasion:

      Caused by: java.lang.IllegalArgumentException: Could not find MonitoredHost for scheme: local
      at jdk.internal.jvmstat/sun.jvmstat.monitor.MonitoredHost.getMonitoredHost(MonitoredHost.java:177)
      at jdk.internal.jvmstat/sun.jvmstat.monitor.MonitoredHost.getMonitoredHost(MonitoredHost.java:133)

      on a different occasion:

      Caused by: java.util.NoSuchElementException
      at java.base/java.util.ServiceLoader$2.next(ServiceLoader.java:1314)
      at java.base/java.util.ServiceLoader$2.next(ServiceLoader.java:1302)
      at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1397)
      at jdk.internal.jvmstat/sun.jvmstat.monitor.MonitoredHost.getMonitoredHost(MonitoredHost.java:170)
      at jdk.internal.jvmstat/sun.jvmstat.monitor.MonitoredHost.getMonitoredHost(MonitoredHost.java:133)

      This is because the method internally uses a shared instance of java.util.ServiceLoader. ServiceLoader is not a thread safe class (as noted in its class javadoc)

      Attachments

        Issue Links

          Activity

            People

              jpai Jaikiran Pai
              jpai Jaikiran Pai
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: