这篇文章来自我的博客
1.本地测试程序
public class TestHeapSpace { private int index; public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } public static void main(String[] args) { List<TestHeapSpace> list=new ArrayList<TestHeapSpace>(); int index=0; while(true) { TestHeapSpace t=new TestHeapSpace(); t.setIndex(index++); list.add(t); } } }
2.eclipse调整内存参数
参数1是限制堆内存大小 参数2是溢出保存堆文件 -Xmx1m -XX:+HeapDumpOnOutOfMemoryError
3.运行程序执行后会生成一个后缀为hprof的文件
4.下载工具 IBM heapAnalyzer
下载后是个jar包 文件名为ha456.jar
5.运行工具
java -jar ha456.jar
6.运行后
这里只是个例子 第一个list占内存最高的
7.tomcat 添加参数
在tomcat启动参数中加入两个参数 set JAVA_OPTS=-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/export/home/tomcat/domains/server2/oom.hprof
还没有评论,来说两句吧...