mac jvisualvm安装Visual GC插件
我的Visual VM主要使用的是idea中的插件,首先在idea中安装 VisualVm Launcher插件。
然后配置VisualVm Launcher的配置
在命令行输入/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/bin/jvisualvm
后回车,打开 jvisualvm的界面,点击 工具->插件
,勾选Visual GC
后点击左下角的安装按钮。
因为插件是在github上面下载的,所以下载的时候可能会有网络的问题,开代理可能也装不上。
这时候,就复制错误信息中的地址,手动下载插件文件。然后在已下载中添加下载的文件,并进行安装。
装好以后,在idea中使用Run With VisualVM
运行程序,在弹出的统计窗中
下面的是一个测试代码,用注释中的JVM参数跑起来,在Visual GC中看到的效果非常炫酷。
package cn.shutdown.demo.jvm;
import java.util.HashMap;
/**
* -Xmx1g -Xms1g -Xmn512k -XX:+UseSerialGC -XX:+PrintGCDetails -Xloggc:StopWorldTestGcLog.log
* @author dmn
*/
public class StopWorldTest {
public static void main(String args[]) {
MyThread t = new MyThread();
PrintThread p = new PrintThread();
t.start();
p.start();
}
public static class MyThread extends Thread {
HashMap map = new HashMap();
@Override
public void run() {
try {
while (true) {
// System.out.println((map.size() * 512) / 1024 / 1024);
if (map.size() * 512 / 1024 / 1024 >= 880) {
map.clear();
System.out.println("clean map");
}
byte[] b1;
for (int i = 0; i < 100; i++) {
b1 = new byte[512];
map.put(System.nanoTime(), b1);
}
Thread.sleep(1);
}
} catch (Exception e) {
}
}
}
public static class PrintThread extends Thread {
public static final long starttime = System.currentTimeMillis();
@Override
public void run() {
try {
while (true) {
long t = System.currentTimeMillis() - starttime;
System.out.println(t / 1000 + "." + t % 1000);
Thread.sleep(100);
}
} catch (Exception e) {
}
}
}
}
还没有评论,来说两句吧...