org.apache.camel.util.concurrent
Class RejectableThreadPoolExecutor

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by java.util.concurrent.ThreadPoolExecutor
          extended by org.apache.camel.util.concurrent.RejectableThreadPoolExecutor
All Implemented Interfaces:
Executor, ExecutorService

public class RejectableThreadPoolExecutor
extends ThreadPoolExecutor

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

See Also:
RejectableFutureTask, Rejectable, RejectableScheduledThreadPoolExecutor

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
 
Constructor Summary
RejectableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)
           
RejectableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)
           
RejectableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory)
           
RejectableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
           
 
Method Summary
protected
<T> RunnableFuture<T>
newTaskFor(Callable<T> callable)
           
protected
<T> RunnableFuture<T>
newTaskFor(Runnable runnable, T value)
           
 
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated
 
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, submit, submit, submit
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RejectableThreadPoolExecutor

public RejectableThreadPoolExecutor(int corePoolSize,
                                    int maximumPoolSize,
                                    long keepAliveTime,
                                    TimeUnit unit,
                                    BlockingQueue<Runnable> workQueue)

RejectableThreadPoolExecutor

public RejectableThreadPoolExecutor(int corePoolSize,
                                    int maximumPoolSize,
                                    long keepAliveTime,
                                    TimeUnit unit,
                                    BlockingQueue<Runnable> workQueue,
                                    ThreadFactory threadFactory)

RejectableThreadPoolExecutor

public RejectableThreadPoolExecutor(int corePoolSize,
                                    int maximumPoolSize,
                                    long keepAliveTime,
                                    TimeUnit unit,
                                    BlockingQueue<Runnable> workQueue,
                                    RejectedExecutionHandler handler)

RejectableThreadPoolExecutor

public RejectableThreadPoolExecutor(int corePoolSize,
                                    int maximumPoolSize,
                                    long keepAliveTime,
                                    TimeUnit unit,
                                    BlockingQueue<Runnable> workQueue,
                                    ThreadFactory threadFactory,
                                    RejectedExecutionHandler handler)
Method Detail

newTaskFor

protected <T> RunnableFuture<T> newTaskFor(Runnable runnable,
                                           T value)
Overrides:
newTaskFor in class AbstractExecutorService

newTaskFor

protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
Overrides:
newTaskFor in class AbstractExecutorService


Apache CAMEL