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 threadTop.bat of threadTop.sh (depending on your OS)
JAVA_HOME need to be set to the JDK version you use.
ThreadTop command line parameters :
threadTop.bat -cad -n 10 -s CPU -i 3 -m 2000 myserver:54321
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 -d -m 20000 -n 10 -i 3 -s CONTEND 13232
Will connect to process id 13232 on local machine. Will take three samples of 20 seconds and will report top 10 contended threads.