How do I keep track when class is loaded and destroyed in jvm? Is there any callback method that is exposed by the jvm?
If you're using a Sun/Oracle JVM, you could use the TraceClassLoading and TraceClassUnloading options. Use the following to see what options your JVM supports:
java -XX:+AggressiveOpts -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version
If these options are supported, run your Java application using -XX:+TraceClassLoading -XX:+TraceClassUnloading. You should see messages like:
[Loaded ... from ...]
[Unloading class ...]