What is the RejectedExecutionHandler in ThreadPoolExecutor? How can you customize it?

RejectedExecutionHandler is the callback interface a ThreadPoolExecutor invokes when it cannot accept a new task — typically because both its worker threads and its task queue are already full — letting you define custom behavior instead of the default hard failure.

Key Points

Example

A high-throughput ingestion service might implement a custom handler that pushes rejected tasks onto a dead-letter queue for later reprocessing instead of silently dropping them or throwing an unhandled exception that could crash the caller.

ThreadPoolExecutor executor = new ThreadPoolExecutor(
    4, 8, 60, TimeUnit.SECONDS,
    new ArrayBlockingQueue<>(100),
    (r, exec) -> {
        // custom handling, e.g. log and route to a fallback
        log.warn("Task rejected, running on caller thread");
        r.run();
    });

Interview Tip

A concise interview answer is

RejectedExecutionHandler defines what happens when a ThreadPoolExecutor can't accept a task because its queue and pool are both full. The built-in options are abort, caller-runs, discard, and discard-oldest, and you can implement your own to log, retry, or route overflow tasks instead of just failing outright.

Last updated: 16 July 2026

Previous question: What is the difference between submit() and execute() methods in the Executor Framework?

Next question: How does ConcurrentHashMap work internally?

More Concurrency and Multithreading interview questions

All Concurrency and Multithreading questions