java
10 minJava Thread Dumps: Find Deadlocks, Starvation, and Lock Contention
Use repeated thread dumps and thread-state patterns to distinguish deadlocks from slow dependencies, starvation, and excessive synchronization.
Loading page...
java
10 minUse repeated thread dumps and thread-state patterns to distinguish deadlocks from slow dependencies, starvation, and excessive synchronization.
Q&A
Q&AUse repeated thread dumps and lock profiling to locate hot locks, then reduce serialization safely.
Capture repeated thread dumps and identify many threads blocked on the same owner or monitor. Use a profiler or JFR lock events to quantify contention and critical-section time. Reduce lock scope, shard independent state, batch updates, or use concurrent primitives only when they preserve the invariant; verify throughput and correctness under representative load.
Q&A
Q&AFind a cycle in lock ownership and waiting, then remove inconsistent nested lock ordering.
Capture repeated thread dumps with jcmd or jstack while the incident is active. A deadlock cycle shows threads waiting for locks held by each other; distinguish it from starvation or a slow dependency by checking whether owners can progress. Fix consistent lock order, shorten critical sections, or redesign ownership so both locks are not required together.
Q&A
Q&APooled threads outlive requests, so forgotten thread-local values can leak data and memory across tasks.
Thread pools reuse worker threads. A ThreadLocal value can remain attached after a request ends, retaining large objects or exposing one request’s context to a later task if it is not overwritten. Clear it in a finally block or use a scoped context mechanism with well-defined propagation and cleanup.
Q&A
Q&AWorkers can all block waiting for child tasks queued to the same exhausted executor.
If every worker submits a task to the same bounded executor and synchronously waits for that task, no worker remains to run queued children. This is thread-pool starvation, not necessarily a monitor deadlock. Avoid blocking composition on the same pool, separate workloads, or use asynchronous completion and bounded concurrency.
distributed systems
15 minReason about leader election across partitions and preserve causal context across Kafka, thread pools, and service boundaries.
Q&A
Q&AAsync routes run on the event loop; sync routes are generally dispatched to a worker thread pool.
An async route can yield during nonblocking I/O, allowing the event loop to serve other work. A normal def route is typically run in a thread pool. Calling blocking I/O inside async def blocks the event loop; using async syntax alone does not improve CPU-bound work. Choose an execution model based on the library and bottleneck.
Q&A
Q&ACompare post-GC live-set size and object retention paths over time.
High allocation can cause frequent collections while post-GC occupancy remains broadly stable. A leak tends to retain objects that should have become unreachable, so compare heap dumps and dominator paths across time. Check allocation rate, live set, GC logs, and process/container memory together before changing heap settings.