diff --git a/vjtop/src/main/java/com/vip/vjtools/vjtop/VMInfo.java b/vjtop/src/main/java/com/vip/vjtools/vjtop/VMInfo.java index 4585c03a..a02f4b83 100755 --- a/vjtop/src/main/java/com/vip/vjtools/vjtop/VMInfo.java +++ b/vjtop/src/main/java/com/vip/vjtools/vjtop/VMInfo.java @@ -362,12 +362,12 @@ private void updateMemoryPool() { codeCache = new Usage(memoryPoolManager.getCodeCacheMemoryPool().getUsage()); - direct = new Usage(jmxClient.getBufferPoolManager().getDirectBufferPool().getMemoryUsed(), - jmxClient.getBufferPoolManager().getDirectBufferPool().getTotalCapacity(), maxDirectMemorySize); + direct = new Usage(jmxClient.getBufferPoolManager().getDirectBufferPoolUsed(), + jmxClient.getBufferPoolManager().getDirectBufferPoolCapacity(), maxDirectMemorySize); // 取巧用法,将count 放入无用的max中。 - long mapUsed = jmxClient.getBufferPoolManager().getMappedBufferPool().getMemoryUsed(); - map = new Usage(mapUsed, jmxClient.getBufferPoolManager().getMappedBufferPool().getTotalCapacity(), + long mapUsed = jmxClient.getBufferPoolManager().getMappedBufferPoolUsed(); + map = new Usage(mapUsed, jmxClient.getBufferPoolManager().getMappedBufferPoolCapacity(), mapUsed == 0 ? 0 : jmxClient.getBufferPoolManager().getMappedBufferPool().getCount()); } catch (Exception e) { diff --git a/vjtop/src/main/java/com/vip/vjtools/vjtop/data/jmx/JmxBufferPoolManager.java b/vjtop/src/main/java/com/vip/vjtools/vjtop/data/jmx/JmxBufferPoolManager.java index e19bf24f..9a792517 100755 --- a/vjtop/src/main/java/com/vip/vjtools/vjtop/data/jmx/JmxBufferPoolManager.java +++ b/vjtop/src/main/java/com/vip/vjtools/vjtop/data/jmx/JmxBufferPoolManager.java @@ -18,6 +18,9 @@ public JmxBufferPoolManager(MBeanServerConnection connection) throws IOException List bufferPoolMXBeans = ManagementFactory.getPlatformMXBeans(connection, BufferPoolMXBean.class); + if (bufferPoolMXBeans == null) { + return; + } for (BufferPoolMXBean bufferPool : bufferPoolMXBeans) { String name = bufferPool.getName().toLowerCase().trim(); @@ -29,11 +32,23 @@ public JmxBufferPoolManager(MBeanServerConnection connection) throws IOException } } - public BufferPoolMXBean getDirectBufferPool() { - return directBufferPool; + public long getDirectBufferPoolUsed() { + return directBufferPool != null ? directBufferPool.getMemoryUsed() : 0; + } + + public long getDirectBufferPoolCapacity() { + return directBufferPool != null ? directBufferPool.getTotalCapacity() : 0; + } + + public long getMappedBufferPoolUsed() { + return mappedBufferPool != null ? mappedBufferPool.getMemoryUsed() : 0; + } + + public long getMappedBufferPoolCapacity() { + return mappedBufferPool != null ? mappedBufferPool.getTotalCapacity() : 0; } - public BufferPoolMXBean getMappedBufferPool() { - return mappedBufferPool; + public long getMappedBufferPoolCount() { + return mappedBufferPool != null ? mappedBufferPool.getCount() : 0; } }