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&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.
Q&A
Q&ACompletion stages form a dependency graph; blocking the wrong executor can starve that graph.
CompletableFuture represents a value that may complete later, with dependent stages triggered on completion. Async methods without an explicit executor commonly use a shared pool; blocking calls there can starve unrelated work. Prefer non-blocking composition, choose an executor suited to the task, set timeouts, and observe exceptional completion rather than calling join() throughout request paths.
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&AAt the destination, atomically with the protected effect.
The destination rejects generations older than its highest accepted token. A lease does not stop a paused worker, and a fence cannot reject an expired generation it has not yet learned is superseded.
Q&A
Q&AEvery later layer is invalidated when an earlier instruction input changes.
If the whole source tree is copied before dependency installation, any source edit changes that COPY layer and invalidates all subsequent build steps. Copy lockfiles first, install from them, then copy source. Confirm the result with build output and a clean build; cache reuse should improve speed, not alter correctness.
Q&A
Q&AUse the form that makes transformation, laziness, and accumulator state easiest to understand.
map is lazy and can be concise with an existing named function; a comprehension often reads better when transformation and filtering are simple. reduce is appropriate for a well-defined associative fold, but sum, any, all, or an explicit loop often communicates intent better. Avoid hidden side effects because they make ordering and debugging difficult.
Q&A
Q&APacket direction and handshake behavior help locate whether loss occurs before or after the destination.
Capture narrowly at the client and, if possible, server. A SYN leaving without a reply suggests routing or filtering; a reset indicates an active rejection or no listener; a completed handshake moves investigation toward TLS or the application protocol. Packet captures can expose sensitive metadata or payloads, so limit capture scope and protect files.