We need to debug a Java application that randomly does stuff it should not do.
To understand the root cause of the issue, we would need to get a stacktrace whenever a specific method is called. This sounds easy (add Thread.dumpStack() in this specific method), however this is a code class from the JDK, hence we do not really want to mess with it (even if we indeed could).
Does anybody know if we can implement some kind of "listener" in the JVM that would detect when a specific method is called and dump the stack trace?
This is a production system, so if the solution is a debugger we would need to have something that has very limited impact on performance.
Thank you for your input.
Use Byteman. It can inject tracing code into a running server pretty easily. Our support team love it. http://www.jboss.org/byteman
"Does anybody know if we can implement some kind of "listener" in the JVM that would detect when a specific method is called and dump the stack trace?
This is a production system, so if the solution is a debugger we would need to have something that has very limited impact on performance."
These requirements are contradictory. Dumping the stack is expensive, no matter how you do it. IMO, what you really need to do is set up a test server and run your investigations there.
FWIW, the simplest and probably least expensive way to do this kind of thing is to insert one of these as the first statement of the method:
log.info("Method called", new Throwable());
new Throwable("method called").printStackTrace(System.out);
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