Operations 11 min read

How to Quickly Diagnose and Resolve Common Java Production Issues

This guide walks through the most frequent Java production problems—high CPU, high load, continuous Full GC, thread‑pool saturation, and NoSuchMethodException—explaining their causes, diagnostic commands, and practical remediation steps to restore service stability.

Alibaba Cloud Developer
Alibaba Cloud Developer
Alibaba Cloud Developer
How to Quickly Diagnose and Resolve Common Java Production Issues

Common Online Issue 1: High CPU Utilization

CPU usage reflects system load; occasional spikes are normal, but sustained high CPU can raise the load average and become dangerous. There is no universal safe threshold—it depends on whether the workload is compute‑intensive or I/O‑intensive.

Root Causes & Diagnosis

jstat -gcutil pid

– view GC and memory usage. arthas thread -n 5 – list the top 5 threads by CPU consumption (including stack traces). ps -ef | grep java – locate the Java process ID. top -Hp pid – find the thread with the highest CPU usage. printf '0x%x' tid – convert a thread ID to hexadecimal. jstack pid | grep tid – display the stack of the identified thread.

Common Online Issue 2: High Load

Load represents the number of active processes, including runnable (CPU‑bound) and uninterruptible (I/O‑bound or kernel‑locked) states. CPU‑heavy tasks increase runnable processes, while I/O‑heavy or lock‑contended tasks increase uninterruptible processes.

Root Causes & Diagnosis

CPU‑bound cases are covered in Issue 1.

Check I/O wait with vmstat to see blocked processes.

Identify blocked threads via jstack -l pid | grep BLOCKED or use a profiler to dump thread stacks and analyze lock contention.

Common Online Issue 3: Continuous Full GC

JVM memory flow: new objects go to Eden; when Eden fills, a Minor GC moves survivors to S0 or S1. Repeated fills eventually promote objects to the old generation, triggering Full GC when the old space is full.

In JDK 1.7 class metadata resides in PermGen; from JDK 1.8 it moves to Metaspace, reducing Full GC caused by massive class loading.

Collectors

Younger generation: ParNew (copying, parallel).

Old generation: CMS (mark‑sweep, may cause fragmentation) with concurrent collection.

Key Parameters

CMSInitiatingOccupancyFraction

– percentage of old‑gen usage that triggers Full GC. UseCMSCompactAtFullCollection – compacts old‑gen after Full GC to reduce fragmentation.

Root Causes & Diagnosis

Promotion failure: survivor space too small, causing premature promotion to old generation.

Large object allocation exhausting available memory.

Old generation holds many objects – use jmap -histo pid | sort -n -r -k 2 | head -10 for top classes by instance count, or jmap -histo pid | sort -n -r -k 3 | head -10 for size.

Dump the heap and analyze object distribution with a profiler.

Common Online Issue 4: Thread‑Pool Saturation

ThreadPoolExecutor with a bounded queue creates new threads up to corePoolSize; excess tasks go to the queue, then up to maximumPoolSize. When both queue and threads are full, new tasks are rejected.

Root Causes & Diagnosis

Downstream high response time leads to thread‑pool exhaustion – apply rate limiting.

Database slow SQL or deadlocks – search logs for “Deadlock found when trying to get lock”, then use jstack or zprofiler to inspect blocked threads.

Java code deadlock – jstack -l pid | grep -E 'BLOCKED|deadlock', dump threads with zprofiler for lock analysis.

Common Online Issue 5: NoSuchMethodException

This exception often stems from JAR conflicts; class‑loading order depends on the operating system. Identify conflicting versions with mvn dependency:tree and resolve them.

Use arthas sc -d ClassName to view loaded classes and detect conflicts.

Trace class loading with +TraceClassLoading.

Common Tools for Troubleshooting

Typical Linux commands: tail -f – follow log files. grep -i – case‑insensitive search; grep -v – invert match; grep -E – extended regex. pgm -b – enable concurrency; pgm -p N – set concurrency level; pgm -A – enable askpass. awk -F "|" '{print $1}' | sort -r | uniq -c – field‑based processing. sed '/2020-03-02 10:00:00/,/2020-03-02 11:00:00/p' filename – time‑range extraction.

Arthas (Alibaba’s open‑source Java diagnostic tool) provides powerful features such as:

Dashboard – real‑time view of threads, memory, GC.

Thread – list busy threads.

Getstatic – read static field values.

Sc – inspect loaded classes (useful for JAR conflict detection).

Sm – view methods of a class.

Jad – decompile classes to investigate logic.

Watch – monitor method arguments, return values, and exceptions.

Trace – measure method call durations.

Tt – record method execution for replay.

Effective troubleshooting combines understanding of underlying principles with the right tooling, enabling faster problem identification and service recovery.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaThread Dumpperformance tuninggc
Alibaba Cloud Developer
Written by

Alibaba Cloud Developer

Alibaba's official tech channel, featuring all of its technology innovations.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.