skip to content

A HotSpot thread dump shows every worker of a small fixed thread pool parked in FutureTask.get, and Thread.print reports no deadlock: what is happening, and how do you prove it?

level: seniorimportance: should knowfreq 50%

answer

  1. tasks waiting on their own pool
  2. no worker left to run the subtasks
  3. a future has no owner thread
  4. no worker parked in getTask

basics

~20 s

Thread-starvation deadlock: each worker runs a task waiting on futures of subtasks queued in the same pool, and no worker is free to run them. HotSpot reports nothing because a FutureTask has no owner thread, so there is no lock cycle.

solid answer

~50 s

It is a **thread-starvation deadlock**. Each worker is running a task that submitted subtasks to the same pool and then blocked on their futures; the subtasks sit in the queue behind it and no worker is free to run them. The dump proves it three ways: every worker of that pool has `ThreadPoolExecutor.runWorker`, then your task, then `FutureTask.get` with `- parking to wait for <0x…> (a java.util.concurrent.FutureTask)`; **no** worker is parked in `ThreadPoolExecutor.getTask`, where an idle one waits for work; and the picture is identical across dumps with CPU idle. HotSpot's deadlock finder follows each wait to an owner thread, such as a monitor's or an owned `java.util.concurrent` lock's, and a `FutureTask` has no owner thread, so it finds no cycle. Add the queue depth, or the futures' tasks found in a heap dump, and the proof is complete.

code

java · 9 lines
java
private final ExecutorService pool = Executors.newFixedThreadPool(4);

Future<Quote> quote(Order order) {
    return pool.submit(() -> {
        Future<Price> price = pool.submit(() -> priceOf(order)); // queued on the same pool
        Future<Stock> stock = pool.submit(() -> stockOf(order));
        return new Quote(price.get(), stock.get());              // blocks a worker of that pool
    });
}

go deeper

for a junior

Recall that a task waiting for another task on its own pool can leave nobody to run that other task.

for a middle

Explain the frames: FutureTask.get above runWorker, and why idle workers would instead sit in getTask.

for a senior

Prove it from a series of dumps, explain why HotSpot's finder only follows owned locks, and separate it from slow-work exhaustion.

for a principal

Discuss banning blocking waits on a pool from inside that pool, and keeping blocking work off the shared common pool by policy.

## What the pattern is A **thread-starvation deadlock** happens when tasks running on a bounded pool wait for other tasks that can only run on that same pool. With four workers and four outer tasks that each submit two inner tasks and call `get()` on them, every worker is occupied by an outer task, the inner tasks wait in the queue, and nobody will ever run them. No lock is involved, which is exactly why the JVM's built-in detection says nothing. Why nested submission deadlocks in general belongs to the concurrency topic on pools. Here the question is how it looks in a HotSpot thread dump, and how to tell it from a pool that is merely busy. ## What each worker looks like Every worker thread of the pool (they share a name prefix) shows the same shape, top to bottom: - `jdk.internal.misc.Unsafe.park` and `LockSupport.park`, with `- parking to wait for <0x…> (a java.util.concurrent.FutureTask)` under the top frame; - `FutureTask.awaitDone` and `FutureTask.get`; - your outer task's frame, the one that called `get()`; - `ThreadPoolExecutor.runWorker` near the bottom, proving the waiting code is itself running **on** the pool. Each worker waits on a **different** `FutureTask` address, one per inner task. That alone distinguishes it from a convoy, where many threads wait on one address. ## The evidence that proves it 1. **Every** worker of the pool is in that shape. Count them against the pool's size: if one worker were free it would pick up an inner task and the knot would loosen. 2. **No** worker is in `ThreadPoolExecutor.getTask`. An idle worker of a `ThreadPoolExecutor` parks there, inside the work queue's `take` or `poll`. Its absence means the pool has nobody left to run queued work. 3. The three dumps are **identical**: same threads, same frames, same `FutureTask` addresses, CPU idle. 4. The futures belong to tasks that are still **queued**. The pool's queue depth shows it directly; a heap dump of the executor's queue shows the inner tasks themselves. ## Why HotSpot reports no deadlock `jcmd <pid> Thread.print` runs HotSpot's deadlock finder after the stacks. It walks from each waiting thread to the thread that owns what it waits for: the owner of a monitor, or the owner of a parked-on blocker when that blocker is an `AbstractOwnableSynchronizer`, such as a `ReentrantLock`'s sync object. A `FutureTask` is not an ownable synchronizer and records no owner thread, so the walk stops at that thread and no cycle is printed. The silence is a limit of the detector, not evidence of health. ## Telling it from plain exhaustion | Signal in the series of dumps | Starvation deadlock | Pool exhausted by slow work | |---|---|---| | Worker top frames | All parked in `FutureTask.get` on their own pool | Working, or waiting on an external call such as a socket read | | Change between dumps | None | Tasks and frames change; work completes | | Workers in `getTask` | None, ever | Appear as soon as load drops | | Processors | Idle | Busy, or idle while waiting on a dependency | ## The common ForkJoinPool variant The same starvation hits the JVM-wide **common ForkJoinPool**, which parallel streams use and which `CompletableFuture.supplyAsync` without an executor uses whenever the common pool's parallelism is at least two. Its worker count is small and derived from the processor count. When tasks on it make blocking calls, such as a synchronous HTTP request or a JDBC query, the dump shows every common-pool worker inside that blocking call, while unrelated work that also relies on the common pool, perhaps a parallel stream in a different module, stops making progress. In the series of dumps, look for three things: - every worker of the common pool sits in the same blocking frame in every dump; - the processors stay idle while that call waits; - tasks submitted to the common pool from elsewhere complete late or not at all. The reading is the same as for a fixed pool: all workers of one pool are blocked, and nothing on that pool can run. ## After the evidence The dump names the code path: the frame that calls `get()` from inside the pool. The fix follows from that frame, typically giving the inner work its own executor or composing the futures without blocking, then a fresh series of dumps under the same load should show workers back in `getTask` between requests.

  • Why does this deadlock appear only under load?
    With fewer outer tasks than workers, some worker is always free to run the inner tasks, so the outer ones finish. Only when outer tasks occupy every worker at once is nobody left, which is why it shows up after a burst and never in a quiet test.
  • If the outer task called get() with a timeout, how would the dumps change?
    Workers would show TIMED_WAITING in the same FutureTask frames, then time out and fail their requests, and the pool would recover once load fell. The dumps then show a recurring stall rather than a permanent one, but the same evidence names it: all workers in get() on their own pool, none in getTask.
  • Would a JSON dump from Thread.dump_to_file name an owner for these waits?
    No. Its parkBlocker carries an owner only when the blocker is an ownable synchronizer with an owner thread, and a FutureTask is neither, so the entry has the FutureTask object and nothing else. The proof still comes from the shape of all the workers together.

  • No Found one Java-level deadlock line means the pool is not deadlocked.
  • Workers parked in FutureTask.get are idle, so the pool has spare capacity.
  • All workers parked on different addresses rules out any kind of deadlock.
  • A starvation deadlock always shows threads BLOCKED on a synchronized monitor.
  • Doubling the pool size fixes it for good.