From c04ef7925977f17566581b81909bb62780b947e9 Mon Sep 17 00:00:00 2001 From: Colin Ingarfield Date: Mon, 27 Jul 2015 15:31:04 -0500 Subject: [PATCH] fix used/max file descriptor counts in oracle java 8 --- .../net/bull/javamelody/JavaInformations.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/javamelody-core/src/main/java/net/bull/javamelody/JavaInformations.java b/javamelody-core/src/main/java/net/bull/javamelody/JavaInformations.java index dd70b0563..fb58737d2 100644 --- a/javamelody-core/src/main/java/net/bull/javamelody/JavaInformations.java +++ b/javamelody-core/src/main/java/net/bull/javamelody/JavaInformations.java @@ -235,9 +235,7 @@ private static long buildProcessCpuTimeMillis() { private static long buildOpenFileDescriptorCount() { final OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean(); - if (isSunOsMBean(operatingSystem) - && "com.sun.management.UnixOperatingSystem".equals(operatingSystem.getClass() - .getName())) { + if (isSunOsMBean(operatingSystem) && isSunUnixMBean(operatingSystem)) { try { return MemoryInformations.getLongFromOperatingSystem(operatingSystem, "getOpenFileDescriptorCount"); @@ -251,9 +249,7 @@ private static long buildOpenFileDescriptorCount() { private static long buildMaxFileDescriptorCount() { final OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean(); - if (isSunOsMBean(operatingSystem) - && "com.sun.management.UnixOperatingSystem".equals(operatingSystem.getClass() - .getName())) { + if (isSunOsMBean(operatingSystem) && isSunUnixMBean(operatingSystem)) { try { return MemoryInformations.getLongFromOperatingSystem(operatingSystem, "getMaxFileDescriptorCount"); @@ -477,6 +473,15 @@ private static boolean isSunOsMBean(OperatingSystemMXBean operatingSystem) { || "sun.management.OperatingSystemImpl".equals(className); } + private static boolean isSunUnixMBean(OperatingSystemMXBean operatingSystem) { + for (Class inter : operatingSystem.getClass().getInterfaces()) { + if ("com.sun.management.UnixOperatingSystemMXBean".equals(inter.getName())) { + return true; + } + } + return false; + } + MemoryInformations getMemoryInformations() { return memoryInformations; }