//操作系统信息
OperatingSystemMXBean osm = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
System.out.println("osm.getName() "+osm.getName()); //名字
System.out.println("osm.getVersion() "+osm.getVersion()); //版本
System.out.println("osm.getArch() "+osm.getArch()); //数据结构(32位、64位)
System.out.println(osm.getFreePhysicalMemorySize()/1024/1024); //空闲内存
System.out.println(osm.getTotalPhysicalMemorySize()/1024/1024); //总内存
//jvm 信息
RuntimeMXBean rmb=(RuntimeMXBean)ManagementFactory.getRuntimeMXBean();
System.out.println("getVmVersion "+rmb.getVmVersion()); //版本
System.out.println("getVmName "+rmb.getVmName()); //名称
System.out.println("getClassPath "+rmb.getClassPath()); //classPath
System.out.println("getLibraryPath "+rmb.getLibraryPath()); //libraryPath
MemoryMXBean mm=(MemoryMXBean)ManagementFactory.getMemoryMXBean();
System.out.println("getHeapMemoryUsage "+mm.getHeapMemoryUsage()); //堆内存
System.out.println("getNonHeapMemoryUsage "+mm.getNonHeapMemoryUsage()); //非堆内存
List<MemoryPoolMXBean> mpmList=ManagementFactory.getMemoryPoolMXBeans(); //内存详细信息 eden suviver old perm
for(MemoryPoolMXBean mpm:mpmList){
System.out.println("getUsage "+mpm.getName()+":"+mpm.getUsage());
}
OperatingSystemMXBean osm = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
System.out.println("osm.getName() "+osm.getName()); //名字
System.out.println("osm.getVersion() "+osm.getVersion()); //版本
System.out.println("osm.getArch() "+osm.getArch()); //数据结构(32位、64位)
System.out.println(osm.getFreePhysicalMemorySize()/1024/1024); //空闲内存
System.out.println(osm.getTotalPhysicalMemorySize()/1024/1024); //总内存
//jvm 信息
RuntimeMXBean rmb=(RuntimeMXBean)ManagementFactory.getRuntimeMXBean();
System.out.println("getVmVersion "+rmb.getVmVersion()); //版本
System.out.println("getVmName "+rmb.getVmName()); //名称
System.out.println("getClassPath "+rmb.getClassPath()); //classPath
System.out.println("getLibraryPath "+rmb.getLibraryPath()); //libraryPath
MemoryMXBean mm=(MemoryMXBean)ManagementFactory.getMemoryMXBean();
System.out.println("getHeapMemoryUsage "+mm.getHeapMemoryUsage()); //堆内存
System.out.println("getNonHeapMemoryUsage "+mm.getNonHeapMemoryUsage()); //非堆内存
List<MemoryPoolMXBean> mpmList=ManagementFactory.getMemoryPoolMXBeans(); //内存详细信息 eden suviver old perm
for(MemoryPoolMXBean mpm:mpmList){
System.out.println("getUsage "+mpm.getName()+":"+mpm.getUsage());
}
Java系统与JVM信息获取
本文介绍了一种使用Java代码来获取操作系统及JVM相关信息的方法。通过ManagementFactory类可以获取到系统的名称、版本、架构等信息,以及JVM的版本、名称、内存使用情况等。同时展示了如何获取堆内存、非堆内存以及各内存池的使用情况。
9万+

被折叠的 条评论
为什么被折叠?



