Name

RejectedExecutionHandler

Synopsis

This interface defines an API for a handler method invoked by a ThreadPoolExecutor when its execute( ) method cannot accept any more Runnable objects. This can occur when both the thread pool and the queue of waiting tasks is full, or when the ThreadPoolExecutor has been shut down. Register an instance of this class with the setRejectedExecutionHandler( ) method of ThreadPoolExecutor. ThreadPoolExecutor includes several predefined implementations of this interface as static member classes. If the rejectedExecution( ) method cannot arrange for the Runnable to be run and does not wish to simply discard that task, it should throw a RejectedExecutionException which propagates up to the caller that submitted the task for execution.

public interface RejectedExecutionHandler {
// Public Instance Methods
     void rejectedExecution(Runnable r, ThreadPoolExecutor executor);  
}

Implementations

ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy

Passed To

ScheduledThreadPoolExecutor.ScheduledThreadPoolExecutor( ), ThreadPoolExecutor.{setRejectedExecutionHandler( ), ThreadPoolExecutor( )}

Returned By

ThreadPoolExecutor.getRejectedExecutionHandler( )

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.