Class RejectableScheduledThreadPoolExecutor

All Implemented Interfaces:
Executor, ExecutorService, ScheduledExecutorService

Scheduled thread pool executor that creates RejectableFutureTask instead of FutureTask when registering new tasks for execution.

Instances of RejectableFutureTask are required to handle ThreadPoolRejectedPolicy.Discard and ThreadPoolRejectedPolicy.DiscardOldest policies correctly, e.g. notify Callable and Runnable tasks when they are rejected. To be notified of rejection tasks have to implement Rejectable interface:

 public class RejectableTask implements Runnable, Rejectable {
     @Override
     public void run() {
         // execute task
     }
     @Override
     public void reject() {
         // do something useful on rejection
     }
 }
 

If the task does not implement Rejectable interface the behavior is exactly the same as with ordinary ScheduledThreadPoolExecutor.

See Also: