← Lessons

quiz vs the machine

Gold1410

Concurrency

The Work Queue and Rejection

What happens when the queue is full.

5 min read · core · beat Gold to climb

Bounded versus unbounded

A pool work queue can be bounded or unbounded. An unbounded queue never rejects, but it can hide overload until memory runs out. A bounded queue applies backpressure by refusing work once full.

Rejection policies

When a bounded queue is full and the pool is at maximum threads, the executor must decide what to do with a new task:

  • Abort throws an error to the submitter.
  • Caller runs executes the task on the submitting thread, slowing the producer.
  • Discard silently drops the newest task.
  • Discard oldest drops the head of the queue to make room.

The caller runs policy is a quiet form of backpressure: it forces the producer to feel the cost of overload.

Choosing a policy

Pick abort when losing work is unacceptable and you want to surface the failure. Pick caller runs when you would rather throttle the producer than drop requests. Discard policies suit telemetry where stale data is worthless.

Key idea

A bounded queue plus a rejection policy is how a pool says enough, turning overload into a visible, controllable signal.

Check yourself

Answer to earn rating on the learn ladder.

1. What does the caller runs rejection policy do?

2. What is a danger of an unbounded work queue?