I have a Tomcat with some applications running. I cannot restart the Tomcat but I would like to monitor the usage of class files.
I would like to log if a specified class is used. Is this possible? How could I accomplish it?
Class Usage: If an object for this class is instantiated or methods are called etc.
Clarification: I cannot restart the application. Every solution with recompiling the running code are not acceptable. That makes the problem so hard.
Remote debugging/JMX is not enabled yet. It would be a similar effort like recompiling the application to activate it.
Platform is RHEL, 64 Bit.
I would like to log if a specified class is used; i.e. if an object for this class is instantiated or methods are called etc.
A memory profiler would tell you if a reachable instance of a class exists at the instant you run the profiler. An execution profiler could tell you that a method or constructor is called during some interval ... though it might also miss a call, due to the way that profilers work.
The webapp's classloader could in theory tell you if a class has been loaded, but I doubt there is a way to call the classloader's method that doesn't involve a restart. Also, there is no way to know if a method has EVER been called or an instance has EVER been created apart from adding monitoring hooks to the class. And adding those hooks would entail a restart.
And of course there are other ways that a class could be "used" that don't entail constructing instances or calling its methods.
So depending on what you are really trying to figure out, you may be out of luck.
I think you need profiling for that. Profiler will allow you to see which classes are used. Or the programmers fav - System.out.println :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With