views:

4048

answers:

3

I would like to monitor the number of threads used by a specific jvm process on linux. Is there an easy way to get this information without impacting the performance of the jvm process.

More specifically I am interested in the number of threads per state.

+3  A: 

JStack is quite inexpensive - one option would be to pipe the output through grep to find active threads and then pipe through wc -l.

More graphically is JConsole, which displays the thread count for a given process.

rhys keepence
+2  A: 

Newer JDK distributions ship with JConsole and VisualVM. Both are fantastic tools for getting the dirty details from a running Java process. If you have to do this programmatically, investigate JMX.

basszero
+3  A: 

try

ps uH p <PID_OF_U_PROCESS> | wc -l

or htop

slav0nic