Quick revision
The short answer
ThreadPoolExecutor has four built-in rejection policies. AbortPolicy, the default, throws RejectedExecutionException so the caller decides; CallerRunsPolicy runs the task on the thread that submitted it, which slows the producer down; DiscardPolicy silently drops the task; and DiscardOldestPolicy drops the oldest queued task and retries the new one. Rejection happens when the queue is full and the pool is at its maximum, and also after shutdown, and we can write our own handler to log, count or redirect.
What to remember
In this answer, we saw that a pool rejects a task when its queue is full and it has reached its maximum threads, and always after shutdown. AbortPolicy, the default, throws and lets the caller respond; CallerRunsPolicy slows the producer by running the task itself, which suits batch producers but hurts request threads; DiscardPolicy drops work silently and needs a counter; DiscardOldestPolicy keeps the newest work by dropping the oldest. A custom handler can add metrics and logs or redirect the task to durable storage.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
ThreadPoolExecutor has four built-in rejection policies. AbortPolicy, the default, throws RejectedExecutionException so the caller decides; CallerRunsPolicy runs the task on the thread that submitted it, which slows the producer down; DiscardPolicy silently drops the task; and DiscardOldestPolicy drops the oldest queued task and retries the new one. Rejection happens when the queue is full and the pool is at its maximum, and also after shutdown, and we can write our own handler to log, count or redirect.
Why this question is asked
Every bounded pool will one day be full, and the rejection policy is the decision we make in advance about what happens then. Choosing the wrong one can lose work silently, block a web server, or make an outage worse. Interviewers ask about the policies because the answer shows whether we think about overload, not just about the happy path. In this answer, we will recap when a pool rejects a task, run each of the four built-in policies on the same tiny pool, compare where each fits, and then see rejection after shutdown and how to write a custom handler.
1When Does a Pool Reject a Task?
A ThreadPoolExecutor accepts a task in one of three ways: it starts a new thread if it has fewer than its core size, it puts the task in its queue if the queue has space, or it starts an extra thread if it is still below its maximum size. If none of these is possible, because the queue is full and the pool already has its maximum number of threads, the task is rejected.
Rejected does not mean thrown away. The pool hands the task to its RejectedExecutionHandler, an interface with one method, rejectedExecution(Runnable task, ThreadPoolExecutor pool), and that handler decides what happens. The JDK ships four handlers as nested classes of ThreadPoolExecutor, and we pick one in the constructor or with setRejectedExecutionHandler().
2Seeing Each Policy on a Tiny Pool
To see the difference, we build a pool with one thread and a queue of one, and submit three tasks that each sleep for a second. The first runs, the second waits in the queue, and the third has nowhere to go, so it is rejected.
Notice that only AbortPolicy tells the caller anything. The two discard policies return normally, so the caller believes the task was accepted. CallerRunsPolicy returns normally too, but only after doing the work itself.
3AbortPolicy and CallerRunsPolicy
AbortPolicy throws RejectedExecutionException, an unchecked exception. It is the default for a good reason: it makes overload visible and lets the code that submitted the task decide what to do, such as return an HTTP 503 to the client, try a fallback, or record a failure. In most services this is the right choice, as long as the caller actually catches the exception and turns it into a sensible response.
CallerRunsPolicy runs the rejected task directly on the thread that called execute(). The effect is a form of backpressure, which means slowing down the producer when the consumer cannot keep up: while the producer is busy running a task, it cannot submit new ones. That fits a batch job where one thread reads a file and feeds a pool, because slowing the reader is exactly what we want. But there is a catch: if the submitting thread is a web server's request thread or an event loop, that thread now does slow background work, and the whole server can slow down.
4DiscardPolicy and DiscardOldestPolicy
DiscardPolicy does nothing at all; the task simply disappears. It only fits work that may be lost, such as best-effort statistics or a cache warm-up, and even then we should count the drops in a metric so that a growing number of losses is visible. A subtle trap: if the task came from submit(), the caller holds a Future for it, and that Future never completes, so a call to get() without a timeout waits forever.
DiscardOldestPolicy removes the task at the head of the queue, which is normally the one that has waited longest, and then tries to execute the new task again. It fits work where only the latest data matters, such as pushing the current price or position to a screen, where an old update is worthless once a newer one exists. Be careful with a priority queue: its head is the highest-priority task, so this policy would drop the most important one.
| Policy | What happens to the new task | Caller sees | Good fit |
|---|---|---|---|
AbortPolicy (default) | not run | RejectedExecutionException | most services: fail fast and respond |
CallerRunsPolicy | runs on the submitting thread | a slow execute() call | batch producers that should slow down |
DiscardPolicy | dropped silently | nothing | losable work, with a drop counter |
DiscardOldestPolicy | replaces the oldest queued task | nothing | latest-value updates such as prices |
5Rejection After Shutdown and Custom Handlers
A pool also rejects tasks after shutdown() has been called, even if it has free threads and an empty queue. With AbortPolicy we get RejectedExecutionException, which is often how we find code that keeps submitting during application stop. The other three built-in policies quietly discard the task once the pool is shut down; CallerRunsPolicy does not run it on the caller in that case.
A custom handler is just an implementation of RejectedExecutionHandler. The most useful ones keep the behaviour of a built-in policy but add a metric and a log line with the pool's state, as above. Others redirect the task, for example writing it to a durable queue to retry later. Whatever the handler does, it should be fast, because it runs on the submitting thread.
6Follow-up questions
Which policy would you choose for a pool that sends emails?
AbortPolicy with a counter, and the caller writes the email to a durable outbox table when the pool rejects it, so a background job sends it later. An email must not be lost, so the discard policies are out, and CallerRunsPolicy would make the request thread wait for the mail server.
Does CallerRunsPolicy guarantee that no task is ever lost?
No. While the pool is running it executes every rejected task on the caller, but after shutdown it discards the task silently. It also does not survive a crash: tasks still in the queue are lost if the JVM dies, like with any in-memory queue.
Why does a task dropped by DiscardPolicy leave a hanging Future?
submit() wraps the task in a FutureTask and passes that to execute(). DiscardPolicy drops the FutureTask without running or cancelling it, so it never reaches a completed state. Anyone calling get() without a timeout blocks forever, which is another reason to prefer counting or failing over silent discarding.
7Conclusion
In this answer, we saw that a pool rejects a task when its queue is full and it has reached its maximum threads, and always after shutdown. AbortPolicy, the default, throws and lets the caller respond; CallerRunsPolicy slows the producer by running the task itself, which suits batch producers but hurts request threads; DiscardPolicy drops work silently and needs a counter; DiscardOldestPolicy keeps the newest work by dropping the oldest. A custom handler can add metrics and logs or redirect the task to durable storage.
Open with
A ThreadPoolExecutor rejects a task when the queue is full and the pool already has its maximum number of threads, and also after it has been shut down.
Then, if they want more
It then calls its RejectedExecutionHandler, and the JDK has four. AbortPolicy is the default: it throws RejectedExecutionException, so the caller knows and can return a 503, use a fallback or save the work somewhere durable. That is what I use in most services. CallerRunsPolicy runs the task on the submitting thread.
That slows the producer down, which is nice backpressure for a batch job reading a file, but dangerous if the caller is a request thread or an event loop, because those threads then do the slow work.
DiscardPolicy silently drops the task, so it only fits work we can lose, and I would count the drops; also a Future from submit never completes in that case. DiscardOldestPolicy drops the oldest queued task and retries the new one, which suits latest-value data like price updates, but not a priority queue, where the head is the most important task.
After shutdown, AbortPolicy throws and the others discard. For anything important I write a small custom handler that keeps fail-fast behaviour but increments a rejection metric and logs active threads and queue size, so overload shows up on the dashboard before users complain.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- java.util.concurrent, package documentation, JLS chapter 17, Threads and Locks
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "List the built-in ThreadPoolExecutor rejection policies and when each fits.": https://scrivio-interview-library.netlify.app/java/executors/cf4891f121/