- jps 工具
查看当前系统中有哪些 java 进程 - jmap 工具(实时的)
查看堆内存占用情况 jmap - heap 进程id - jconsole 工具
图形界面的,多功能的监测工具,可以连续监测
案例1:
代码
public class Demo1_4 {
public static void main(String[] args) throws InterruptedException {
System.out.println(“1…”);
Thread.sleep(30000);
byte[] array = new byte[1024 * 1024 * 10]; // 10 Mb
System.out.println(“2…”);
Thread.sleep(20000);
array = null;
System.gc();
System.out.println(“3…”);
Thread.sleep(1000000L);
}
}
第一步jps获得java进程id
D:\study\ideaworkspace\jvmtiaoyou>jps
1924 Launcher
12168 Launcher
17544 RemoteMavenServer36
5752
11948 Jps
1580 Launcher
20060 Demo1_4
第二部 jmap -heap 20060获得进程堆使用具体情况,通过不同时间段调用看到堆内存使用情况
!](https://img-blog.csdnimg.cn/20201020235638404.png#pic_center)
jconsole 实时监测
案例二
jvisualvm 堆转储
dump数据下来分析,某个时间节点的堆内存详情
查看那个对象引起的堆内存过大
以上问题代码
public class Demo1_13 {
public static void main(String[] args) throws InterruptedException {
List students = new ArrayList<>();
for (int i = 0; i < 200; i++) {
students.add(new Student());
// Student student = new Student();
}
Thread.sleep(1000000000L);
}
}
class Student {
private byte[] big = new byte[1024*1024];
}