Skip to content

Commit

Permalink
vjtop-1.0.5在 jdk1.7.0_80运行空指针异常 #144
Browse files Browse the repository at this point in the history
兼容读不到BufferPool的情况。
  • Loading branch information
calvin1978 committed Nov 26, 2018
1 parent 2a41b56 commit 265fd55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 4 additions & 4 deletions vjtop/src/main/java/com/vip/vjtools/vjtop/VMInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public JmxBufferPoolManager(MBeanServerConnection connection) throws IOException

List<BufferPoolMXBean> bufferPoolMXBeans = ManagementFactory.getPlatformMXBeans(connection,
BufferPoolMXBean.class);
if (bufferPoolMXBeans == null) {
return;
}

for (BufferPoolMXBean bufferPool : bufferPoolMXBeans) {
String name = bufferPool.getName().toLowerCase().trim();
Expand All @@ -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;
}
}

0 comments on commit 265fd55

Please sign in to comment.