Mapping Linux Thread IDs to Java Thread Names Using top and jstack: Investigation of JDK Thread Naming Bug
This article demonstrates how to combine Linux top with -H -p options and jstack to correlate Java thread IDs with their logical names, explains the underlying JDK thread‑naming bug, and provides practical recommendations for performance debugging on different JDK versions.
The article explains how to use Linux top with -H -p options together with jstack to map Java thread IDs to their logical names, addressing the limitation of top showing only generic "java" thread names.
It demonstrates the command to list Java threads:
top -H -p `pidof java`and the command to capture a Java stack trace:
jstack -l `pidof java` > /tmp/dble_jstack.logTo identify a specific thread, the article shows converting a thread ID to hexadecimal and grepping the jstack output, for example:
printf "%x\n" 10849
2a61
cat /tmp/dble_jstack.log | grep "nid=0x2a61"The investigation reveals that older Oracle JDK 8 versions do not display thread names in top , while OpenJDK 8 after update 222 fixes this by invoking pthread_setname_np via dlsym , truncating names to the first 15 characters.
Recommendations include upgrading to a recent OpenJDK version, keeping thread names within 15 characters for visibility, and using the native top + jstack workflow to diagnose high‑CPU Java processes, noting that most CPU spikes are caused by GC or NIO epoll bugs.
Reference links to JDK bug reports and Linux man pages are provided for further reading.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.