直播软件搭建,java代码获取内存信息
直播软件搭建,java代码获取内存信息
一、获取堆外内存
@GetMapping("/panama") public Map<String, Object> panama() { ByteBuffer buffer = ByteBuffer.allocateDirect(1 * 1024 * 1024); Map<String, Object> map = new HashMap<>(); try { MBeanServer mbs = ManagementFactory. getPlatformMBeanServer() ; ObjectName objectName = new ObjectName("java.nio:type=BufferPool,name=direct" ) ; MBeanInfo info = mbs.getMBeanInfo(objectName) ; for(MBeanAttributeInfo i : info.getAttributes()) { map.put(i.getName(), mbs.getAttribute(objectName , i.getName())); } } catch (Exception e) { map.put("error", e); } return map; }
输出结果
Name:direct Count:1 TotalCapacity:1048576 MemoryUsed:1048576 ObjectName:java.nio:type=BufferPool,name=direct
以上就是 直播软件搭建,java代码获取内存信息,更多内容欢迎关注之后的文章