How can I debug a java hanging thread?

I have the following problem:
I am deploying a web application to Tomcat (Linux) and after completing Tomcat, if I execute ps -ef , I still see the java process. I believe this is due to some hanging thread, but I don't know how I can track this thread.
How can I debug this problem?

+8
java debugging multithreading tomcat
source share
2 answers

You can generate 4-5 stream dumps as described below, and then analyze them using tools such as Samurai .

What do you want to check when a stuck thread or a long transaction occurs, all thread dumps show that a specific thread identifier is on the same line in your java stack trace. In simpler terms, a transaction covers several dumps of flows and, therefore, requires further study.

Now, when you run them through Samurai , he will highlight them in red so that you can quickly click on it and go to the lines showing the problems.

See an example of this here . Look at the output image of the samurai in this link. Green cells are beautiful. Red and gray cells need to be searched.

Creating a stream dump:

(Linux)

If the JVM is running in the console, just press Ctrl-\ . If the JVM is running in the background, send a QUIT signal to it:

kill -QUIT process_id

Here process_id is the process number of the running Java process. A stream dump will be sent to where the standard output is also redirected. You can usually get the process numbers of all running Java processes using the command:

ps axf | grep java

+5
source share

You say your Java process still exists, right? Processes exist as long as they attach threads, right? If so, I would go for the following approach: - start the process with the MBean server connected and managed inside the JVM

Then connect to the process after sending the QUIT signal and get a stream dump (there must be JMX for this. See which threads look suspicious to you.

I think you can also use JVisualVM to dump threads ...

+2
source share

All Articles