How to unload stacktrace when calling a specific Java method?

We need to debug a Java application that randomly does things that it shouldn't do.

To understand the root cause of the problem, we need to get a stack when a particular method is called. It sounds simple (add Thread.dumpStack()to this particular method), however it is a code class from the JDK, so we really don't want to mess with it (even if we really could).

Does anyone know if we can implement some kind of “listener” in the JVM that will detect when a particular method is called and unload the stack trace?

This is a production system, so if the solution is a debugger, we will need to have something that has a very limited impact on performance.

Thanks for your input.

+3
source share
7 answers

Use Byteman. It can easily enter trace code into a running server. Our support team loves this. http://www.jboss.org/byteman

+2
source

"Does anyone know if we can implement some kind of" listener "in the JVM that will detect when a particular method is called and removes the stack trace?

This is a production system, so if the solution is a debugger, we will need to have something that has a very limited impact on performance.

. , , . , .

FWIW, , , - :

    log.info("Method called", new Throwable());

    new Throwable("method called").printStackTrace(System.out);
+1

, , .

0

-, ,

log.info("Method called", new Throwable("HERE"));
0

java.lang.reflect.Proxy. - .

, , , 1 AOP.

0

java instrumentation api.

java- api - , (, ). Java- javassist github.

https://github.com/kreyssel/maven-examples/tree/master/javaagent

LoggerAgent.java Thread.dumpStack().

, - java.

-javaagent:jarpath[=options]

, .

0

All Articles