NOTE
Java Production Issue Troubleshooting
Java production troubleshooting can start by finding resource-heavy processes with tools such as top, then locating related threads or code. These notes record diagnostic steps.
This is a historical learning note and may contain outdated or incomplete understanding.
1. 100% Memory Usage / Memory Problems
1.1. Find the Java Process ID
Run top, then press M to see which Java process is using the most memory.
1.2. Analyze Whether OOM Has Occurred
2. 100% CPU Usage / Thread Problems
2.1. Find the Java Process ID and Thread ID
- Run
top, pressPto see which Java process has high load, and record its PID. - Run
top -Hp <PID from step 1>to view the running state of all threads in that process. - Record the high-load thread ID and run
printf "%x\n" <PID from step 1>to convert it to hexadecimal.
2.2. Analyze the Thread Dump File
- Run
jstack <PID from step 1> > <file>to generate a jstack file containing stack states. - In the jstack file from step 4, find the thread whose
nidequals the hexadecimal thread ID from step 3. - Use the stack trace to understand what task the thread is executing, then combine that with the business context and code to locate the problem.
3. Thread Deadlock
3.1. Find the Java Process ID
There are two methods:
- Use
topto find the PID whose STATE issleepingand COMMAND isjava. - Use
jps.
3.2. Analyze the Thread Dump File
jstack -l PID
Check for cyclic lock acquisition.
4. JVM Tuning
5. References
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub