通过自动刷新的JSP记录Tomcat当前的Free Memory

大师Z教的:每5秒记录一下内存,写到一个文件里,然后利用Excel画一下图就行了

<meta http-equiv="refresh" content="5">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.io.*"%>


<%
	Runtime lRuntime = Runtime.getRuntime();
	long freeM = lRuntime.freeMemory() / 1024 / 1024;

	out.println("Free  Memory: " + freeM + "M<br/>");

	File file = new File("c:/temp/tomcat_jvm.csv");
	Writer writer = new FileWriter(file, true);
	String content =  ""+freeM;
	writer.write(content);
	writer.write("\n");
	writer.close();
%>

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.