5

I have a piece of running java software that is jammed. I would like to get a view inside but have got no idea how to do that.

Is there some tool that I can give a PID and it will tell me where every thread is currently located and maybe a few values of the variables as well? I'm running linux.

I more or less know what is causing the problem, but there a still a few possible cases, therefor pinpointing it would be nice.

I can't reproduce the error because it only appears every few days and never appeared while debugging, so this is a unique change of getting to know the enemy.

Any ideas?

asked Nov 14, 2011 at 19:04
1

3 Answers 3

13

Actually you can try to use visualvm + its threads monitoring plugin. You will be also able to make a thread dump, view thread stack traces ant their states. You can also use jconsole to detect deadlocks. Both tools are part of JDK. JConsole

Here is some more info on using visualvm for thread analysis.

answered Nov 14, 2011 at 19:16
Sign up to request clarification or add additional context in comments.

Comments

4

You can take a thread dump of it. You can use kill -3 PID where PID is your process ID. This will cause the thread dump to be output to the standard output of your program.

This will show you what every thread is doing, but will not give you any info regarding the variables. Regardless, thread dumps are really useful. I would start there. If you still can't fix the problem, you can use something like jmap (JVM tool, free but harder to use) or YourKit (paid product but very good) to take a memory snapshot, and examine the variables.

Some info on jmap: Java memory profiling with jmap and jhat

Kevin Panko
8,59519 gold badges52 silver badges64 bronze badges
answered Nov 14, 2011 at 19:08

3 Comments

kill -3 PID doesn't seem to do anything. The JVM is still alive afterwards aswell. How can that be?
kill -3 won't actually kill the JVM, it just sends a signal to trigger a thread dump. The thread dump will go to the standard output of the JVM (not the std output of the kill command). Just make sure you're capturing the std output to a file. How are you running your program? Is it a standalone app, or are you running inside an app server like Tomcat? If for example, you're using Tomcat, the std output is in logs/catalina.out. If standalone, you can pipe your std ouput to some file by starting your app with something like: "java -jar myjar.jar > output.log". Hope this helps.
In your standalone case, what if you can't rerun the application, because it's production and it's already running, how can you direct your thread dump to a file?
0

On recent JVMs (OpenJDK/Oracle Java 7 or above), if you take a heap dump (using either VisualVM or jmap), it also includes a dump of the stacks of all currently running threads, with links to the corresponding objects in the heap. You can then view the stacks by opening the heap dump in VisualVM.

answered Jul 4, 2017 at 17:03

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.