0

Situation:

I have a Java1.7 process running in CentOS6 with multiple threads. The process currently halts (i.e., stuck in some kind of loop or waiting function). Due to the complexity nature of the program, it is difficult to do a routine debug in, for instance, Eclipse (more explanation in the background section below). Therefore, I'd like to debug the code by tracing the current running stack.

Question:

Is there a Linux command that would allow me to print the stack to identify the thread/method that is currently running such that I can find which method is causing the halt?

Background:

The reasons for not being able to debug in Eclipse:

  1. It is a MapReduce program typically run on multiple computers.
  2. Even if I use run on one computer, it still involves multiple threads running simultaneously.
  3. Most importantly, the "halting bug" occurs randomly (i.e., not being able to reproduce). So my best shot is to identify the current running method that caused the bug.

P.S. My approach may be completely wrong, so feel free to correct me and point me in the right direction.

Thanks for your help.

2 Answers 2

3

You can use JStack to get the current thread dump. It should give you currently running threads and their stack traces.

It will even do more for you - should there be any deadlocks present it will tell you about them.

Apart from that you can also use JVisualVM to monitor your application in real time (you can check threads in real time there and take thread dumps from it).

Sign up to request clarification or add additional context in comments.

1 Comment

That's really helpful. Thumbs up.
1

From RedHat:

Following are methods for generating a Java thread dump on Unix:

1) Note the process ID number of the Java process (e.g. using top, a grep on ps -axw, etc.) and send a QUIT signal to the process with the kill -QUIT or kill -3 command. For example:

kill -3 JAVA_PID

Comments

Your Answer

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.