启动jconsole
jconsole是jdk自带的一款监控工具,启动方式如下:
启动之后首页:
自己写一段代码测试监控效果
public class JconsoleTest {
public byte[] bytes = new byte[128 * 1024];
public static void main(String[] args) {
try {
//增加等待是为了方便去操作jconsole
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("start ...");
fill(1000);
}
private static void fill(int n) {
List<JconsoleTest> list = new ArrayList<>();
for(int i=0; i<n; i++){
try {
//增加等待方便观察监控效果
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
list.add(new JconsoleTest());
}
}
}
启动后,选中相应的进程连接监控,如下图:
途中显示的是Eden区的内存使用情况,有增有减说明正在创建对象和回收对象。