Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see what my Java process is doing right now?

I have an app server process that's constantly at 100% CPU. By constantly I mean hours, or even days.

I know how to generate a heap/thread dump, but I'm looking for more dynamic information. I would like to know what is using so much CPU in there. There are tens (or probably 100+) threads. I know what those threads are, but I need to know which of them are using my CPU so much.

How can I obtain this information?

like image 929
Konrad Garus Avatar asked Dec 21 '22 08:12

Konrad Garus


2 Answers

Use a profiler. There is one included in VisualVM which comes with the Oracle JDK.

An advanced commercial one (trial licenses available) is YourKit.

like image 138
Arnout Engelen Avatar answered Jan 08 '23 13:01

Arnout Engelen


By creating a thread dump. You can use the jstack to connect to a running java process to get the thread dump. If you take two or more thread dumps over a period of time you can by analyzing them figure out which ones are actively using CPU. Typically the threads in the RUNNING state are the ones you need to focus on.

like image 37
gkamal Avatar answered Jan 08 '23 11:01

gkamal