ThreadTop is a simple command line tool which uses JMX protocol to connect to a Java process. After connection established it will display the list of threads.
The threads are sorted either by CPU consumption, by contention time or by byte allocation. The tool uses Hotspot JMX APIs to extract the relevant data.
The tool is provided with source code under the Apache License v2.0. The source code is located at github. Github project is https://github.com/lifey/Java-threadTop.git
While very simple it can be a very powerful aid when used together with jstack. It can help focus on the threads which consume the highest CPU or suffer from most contention.
Requires: Java 1.5 and above. the monitored process need to be configured with remote JMX enabled:
(The tool supports authentication)
If process is on local machine and process supports attach mechanism (Java 1.6 and above ) tool may connect via process id
Note: This version is a preliminary initial implementation comments are welcome....
Extract the zip file and run java -jar threadTop-1.0-SNAPSHOT.jar
ThreadTop command line parameters :
threadTop.bat myserver:54321 -cad -n 10 -s CPU -i 3 -m 2000
Will connect to myserver at port 54321. Will take three samples of two seconds and will report both CPU contention time and allocation. It will display the 10 most CPU intensive threads.
threadTop.bat 13232 -m 20000 -n 10 -i 3 -s CONTEND
Will connect to process id 13232 on local machine. Will take three samples of 20 seconds and will report top 10 contended threads.