JVM虚拟机内存量详细显示--JSP网页版

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




JVM memory


<%
double total = (Runtime.getRuntime().totalMemory()) / (1024.0 * 1024);
double max = (Runtime.getRuntime().maxMemory()) / (1024.0 * 1024);
double free = (Runtime.getRuntime().freeMemory()) / (1024.0 * 1024);
int totalInt = (int)total;
int maxInt = (int)max;
int freeInt = (int)free;
int realnum = (int)(max - total + free);

out.println("Java 虚拟机试图使用的最大内存量(当前JVM的最大可用内存)maxMemory():  " + maxInt + "  MB

"); out.println("Java 虚拟机中的内存总量(当前JVM占用的内存总数)totalMemory(): " + totalInt + " MB

"); out.println("Java 虚拟机中的空闲内存量(当前JVM空闲内存)freeMemory(): " + freeInt + " MB

"); out.println("因为JVM只有在需要内存时才占用物理内存使用,所以freeMemory()的值一般情况下都很小,

而JVM实际可用内存并不等于freeMemory(),而应该等于 maxMemory()-totalMemory()+freeMemory()。

"); out.println("JVM实际可用内存: " + realnum + " MB"); %>

你可能感兴趣的:(架构设计)