jvm檢視類的引用及建立
阿新 • • 發佈:2019-02-13
1、jmap檢視建立的例項 解決一次Spring註解生成空bean的過程。
原因:ContextLoaderListener和DispatcherServlet 父子關係導致的空bean。
首先檢視埠 FanXin為執行類
檢視目標類例項個數 Student為類名
dump出程序映象
jhat檢視引用關係
登陸localhost:7000 檢視類的引用關係
References to this object:引用該實體類的物件
ce shi dai ma
public class Student { private int id; private String name; public Student(int id,String name){ this.id=id; this.name=name; } public void setId(int id){ this.id=id; } public void setName(String name){ this.name=name; } public int getId(){ return id; } public String getName(){ return name; } }
public class FanXin { private static Student student=new Student(1,"zcl"); public Student getStudent(){ return student; } public static void main(String[]args){ FanXin fanXin=new FanXin(); Student student=fanXin.getStudent(); while(true){ int id=student.getId(); } // System.out.println(student.getId()); } }