0

I work on very large web project which is written in java. when I click some button or do other actions it is hard to me to understand what methods called in application code(because I am new in project and application is really really big). So I would like to know is there a tool which will allow to get stacktrace of some threads with given interval (say every 100 milliseconds ). I know about VisualVm but it does not allow to do this, I can get thread dumb only at one point of time( there is no way to get stack trace continuously).

Can someone suggest tool or any technique which will allow me to monitor methods call at run-time.? Thanks

user1321466
  • 1,889
  • 2
  • 21
  • 29
  • 1
    I doubt there's a way to do this. A Profiler will do something similar, but it's geared towards counting usage, not producing stack traces. I think your best bet is to take one specific use case that you need, and trace that in a debugger. Over time you'll learn the whole app. – markspace Feb 09 '15 at 16:25

3 Answers3

1

There are multiple ways in which you could check stacktrace:

  • Using jconsole's thread tab where you will get to see which all threads are alive and what state they are at.
  • Using JvisualVm (which comes fee with jdk installation) or you could use any of profilers like jprofiler/yourkit etc. to view stack trace when you run in development mode.
  • You could get stack trace say every minute by running kill -3 pid in unix or control + break on windows
  • You could use jstack command to get trace.
  • You could debug the code using say IDE (eclipse/netbeans/Intellij etc.)and after each and every method call trace the method call.
SMA
  • 36,381
  • 8
  • 49
  • 73
1

For such cases I use Java Mission Control. The full features works on Oracle JDK, for OpenJDK not everything works properly. More info

From the website:

Starting with the release of Oracle JDK 7 Update 40 (7u40), Java Mission Control is bundled with the HotSpot JVM.

You need to add the following parameters in your JVM to be able to use it. note: I normally add also the debug options.

JAVA_DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n"
JAVA_JMC="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=3614 -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false -XX:+UnlockCommercialFeatures -XX:+FlightRecorder"

Then you'll need to remote attach to port 3614 and you'll be able to see inside the JVM. There you'll be able to profile CPU, check allocation and deadlock detection + select the thread and see what is currently executing. And some other graphs and valuable information.

  • Thank you very much , I am checking it now, (I am on JDK 6(( ) I will accept your answer once I tested it, but anyway Thanks )) – user1321466 Feb 09 '15 at 16:48
  • You're welcome, if you get the chance to move to JDK7 or JDK8 you'll gain in performance. JDK6 was an in between release when Oracle was taking over Sun. And the big deal comes with JDK8. –  Feb 09 '15 at 16:50
1

Many tools for Java VM monitoring and application monitoring exist. For instance, see the eG Java Application Monitor:

...the eG Java Monitor gives you a comprehensive view of the activities within a JVM:

  • It lets you see which threads are running in the JVM and what state they are in (such as runnable, blocked, waiting, timed waiting, deadlocked, or high CPU).
  • You also have access to a stack trace for each thread showing class, method, and line of code (to troubleshoot problems down to the line of code level).
  • And you can monitor the performance of garbage collection processes, CPU and memory usage, and JVM restarts.
reuben
  • 3,360
  • 23
  • 28
Mark Smith
  • 11
  • 1