How to track when class is loaded and destroyed in jvm?

后端 未结 8 1328
醉梦人生
醉梦人生 2020-12-24 02:25

How do I keep track when class is loaded and destroyed in jvm? Is there any callback method that is exposed by the jvm?

8条回答
  •  -上瘾入骨i
    2020-12-24 03:11

    You can use static block to detect class loading but you can not detect class unloading. In java all classes loaded through the system classloader will never be unloaded and all classes loaded through other classloaders will be unloaded only when the classloader is unloaded.

    static{ 
    
            //execute when the class will be loaded
    
        }
    

提交回复
热议问题