Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

List the built-in ThreadPoolExecutor rejection policies and when each fits.

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.

Java
static ThreadPoolExecutor tiny(RejectedExecutionHandler policy) {
return new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1), policy);
}
static Runnable task(String name) {
return () -> { sleep(1000); System.out.println(name + " ran on " + Thread.currentThread().getName()); };
}
// AbortPolicy (the default)
var p = tiny(new ThreadPoolExecutor.AbortPolicy());
p.execute(task("A")); p.execute(task("B"));
p.execute(task("C")); // throws RejectedExecutionException: C never runs
// CallerRunsPolicy
p = tiny(new ThreadPoolExecutor.CallerRunsPolicy());
p.execute(task("A")); p.execute(task("B"));
p.execute(task("C")); // C ran on main: the submitting thread is busy for 1 s
// DiscardPolicy
p = tiny(new ThreadPoolExecutor.DiscardPolicy());
p.execute(task("A")); p.execute(task("B"));
p.execute(task("C")); // returns at once; C is dropped, nothing is logged
// output: A ran on pool-3-thread-1, B ran on pool-3-thread-1
// DiscardOldestPolicy
p = tiny(new ThreadPoolExecutor.DiscardOldestPolicy());
p.execute(task("A")); p.execute(task("B"));
p.execute(task("C")); // B is removed from the queue, C takes its place
// output: A ran on pool-4-thread-1, C ran on pool-4-thread-1

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.

Built-in rejection policies
PolicyWhat happens to the new taskCaller seesGood fit
AbortPolicy (default)not runRejectedExecutionExceptionmost services: fail fast and respond
CallerRunsPolicyruns on the submitting threada slow execute() callbatch producers that should slow down
DiscardPolicydropped silentlynothinglosable work, with a drop counter
DiscardOldestPolicyreplaces the oldest queued tasknothinglatest-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.

Java
RejectedExecutionHandler countingAbort(MeterRegistry registry, String pool) {
Counter rejected = Counter.builder("executor.rejected").tag("name", pool).register(registry);
return (task, executor) -> {
rejected.increment(); // visible on the dashboard
log.warn("{} rejected a task: active={}, queued={}", pool,
executor.getActiveCount(), executor.getQueue().size());
throw new RejectedExecutionException(pool + " is full"); // still fail fast
};
}

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.

What to say in the interviewAbout 90 seconds aloud

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.
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/