public Map<String, BufferPoolStats> getBufferPoolStats() { try { final String[] attributes = { "Count", "MemoryUsed", "TotalCapacity" }; final ObjectName direct = new ObjectName("java.nio:type=BufferPool,name=direct"); final ObjectName mapped = new ObjectName("java.nio:type=BufferPool,name=mapped"); final AttributeList directAttributes = mBeanServer.getAttributes(direct, attributes); final AttributeList mappedAttributes = mBeanServer.getAttributes(mapped, attributes); final Map<String, BufferPoolStats> stats = new TreeMap<String, BufferPoolStats>(); final BufferPoolStats directStats = new BufferPoolStats((Long) ((Attribute) directAttributes.get(0)).getValue(), (Long) ((Attribute) directAttributes.get(1)).getValue(), (Long) ((Attribute) directAttributes.get(2)).getValue()); stats.put("direct", directStats); final BufferPoolStats mappedStats = new BufferPoolStats((Long) ((Attribute) mappedAttributes.get(0)).getValue(), (Long) ((Attribute) mappedAttributes.get(1)).getValue(), (Long) ((Attribute) mappedAttributes.get(2)).getValue()); stats.put("mapped", mappedStats); return Collections.unmodifiableMap(stats); } catch (JMException e) { return Collections.emptyMap(); } } }