NOTE
Java Production Issue Troubleshooting
Troubleshooting memory saturation, CPU/thread problems, deadlocks, JVM tuning, and related references.
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" <thread ID>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
Analyze whether there is a cyclic locking situation.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub