乐趣区

关于jvm:Mac-18-如何使用jhsdb-调试

1、运行命令,输出明码 即可弹出
sudo java -cp $JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.HSDB
2、创立类,代码如下

/**
 * @author 
 * JVM 参数
 * -Xms30m -Xmx30m  -XX:MaxMetaspaceSize=30m  -XX:+UseConcMarkSweepGC -XX:-UseCompressedOops
 *
 *
 */
public class JVMObject {
    public final static String MAN_TYPE = "man"; // 常量
    public static String WOMAN_TYPE = "woman";  // 动态变量
    public static void  main(String[] args)throws Exception {Teacher T1 = new Teacher();
        T1.setName("李四");
        T1.setSexType(MAN_TYPE);
        T1.setAge(36);
        for(int i =0 ;i<15 ;i++){System.gc();// 被动触发 GC 垃圾回收 15 次 --- T1 存活
        }
        Teacher T2 = new Teacher();
        T2.setName("张三");
        T2.setSexType(MAN_TYPE);
        T2.setAge(18);
        Thread.sleep(Integer.MAX_VALUE);// 线程休眠
    }
}

class Teacher{
    String name;
    String sexType;
    int age;

    public String getName() {return name;}
    public void setName(String name) {this.name = name;}

    public String getSexType() {return sexType;}
    public void setSexType(String sexType) {this.sexType = sexType;}
    public int getAge() {return age;}
    public void setAge(int age) {this.age = age;}
}

运行代码,运行之前请先设置虚拟机参数(垃圾回收器 CMS)
-Xms30m -Xmx30m -XX:MaxMetaspaceSize=30m -XX:+UseConcMarkSweepGC -XX:-UseCompressedOops

3、在命令行上 jps 命令查看该类的过程 ID

退出移动版