如何查看JVM的内存使用情况?

Runtime run = Runtime.getRuntime(); 

long max = run.maxMemory()/(1024*1024); 

long total = run.totalMemory()/(1024*1024); 

long free = run.freeMemory()/(1024*1024); 

long usable = max - total + free; 

System.out.println("最大内存 = " + max); 
System.out.println("已分配内存 = " + total); 
System.out.println("已分配内存中的剩余空间 = " + free); 
System.out.println("最大可用内存 = " + usable); 

猜你喜欢

转载自blog.csdn.net/qq_34309305/article/details/79260547