I am inspecting a Java process in Linux using
top -H
However, I cannot read the name of the thread in the "COMMAND" column (because it is too long). If I use 'c' to expand the full name of the process, then it is still to long to fit.
How can I obtain the full name of the command?
This shell script combines the output from jstack and top to list Java threads by CPU usage. It expects one argument, the account user that owns the processes.
Name: jstack-top.sh
You can inspect java threads with the tool
jstack
. It will list the names, stacktraces and other useful information of all threads belonging to the specified process pid.Edit: The parameter nid in the thread dump of jstack is the hex version of the LWP that is displayed by top in the pid column for threads.
With OpenJDK on Linux, JavaThread names don't propagate to native threads, you cannot see java thread name while inspecting native threads with any tool.
However there is some work in progress:
Personally, I find the OpenJDK development tool slow so I just apply patches myself.
Old question, but I had just the same problem with
top
.It turns out, you can scroll top's output to the right simply by using the cursors keys :)
(but unfortunately there won't be any thread name shown)
As far as I found out jstack is outdated as of JDK 8. What I used to retrieve all Java Thread names is:
Check jcmd documentation for more.
Threads don't have names as far as the kernel is concerned; they only have ID numbers. The JVM assigns names to threads, but that's private internal data within the process, which the "top" program can't access (and doesn't know about anyway).