A Practical Arthas Workflow for Troubleshooting Java in Production

A structured workflow for using Arthas to inspect processes, thread states, slow methods, and the code actually loaded by a running JVM.

When an API suddenly becomes slow, restarting the service should not be the first response. A restart may temporarily restore service, but it also destroys the most valuable runtime evidence. Arthas can inspect a running JVM without changing application code.

Confirm the scope

Before running commands, record:

  • The affected APIs or jobs.
  • When the problem started and whether traffic changed.
  • CPU, memory, GC, thread pool, and database connection pool metrics.
  • Recent releases, configuration changes, and downstream failures.

Every command should test a hypothesis. Avoid enabling expensive observation on high-frequency production methods without limits.

Inspect the JVM and threads

Use dashboard for a high-level view of threads, heap usage, and GC. Then inspect high-CPU or blocked threads:

1
2
3
dashboard
thread -n 10
thread --state BLOCKED

If many threads wait for the same lock, inspect their stacks. If they are waiting on remote calls, move the investigation toward downstream latency, timeouts, and connection pools.

Locate slow methods

trace shows the time spent at each node in a call chain:

1
trace com.example.OrderService queryOrder '#cost > 100'

Filtering by execution time reduces noise and runtime overhead. After identifying a suspicious method, use watch to inspect only the necessary arguments, return values, or exceptions.

Always limit the number of observations and output depth. Avoid printing large objects or observing extremely hot methods.

Verify the loaded code

When a release appears not to have taken effect, use sc, sm, and jad to inspect loaded classes, methods, and decompiled bytecode. The classloader command helps identify which class loader loaded a class.

Build an evidence chain

A useful incident conclusion connects monitoring symptoms, thread or trace evidence, the root cause, immediate mitigation, and the permanent fix. For example, an apparently slow Java method may ultimately be waiting for an exhausted database connection pool.

Arthas shortens the distance between a symptom and runtime evidence. Use the smallest observation scope possible and record the commands, timestamps, and conclusions for the incident review.

Built with Hugo
Theme Stack designed by Jimmy