Search in sources :

Example 1 with RejectableScheduledThreadPoolExecutor

use of org.apache.camel.util.concurrent.RejectableScheduledThreadPoolExecutor in project camel by apache.

the class DefaultThreadPoolFactory method newScheduledThreadPool.

@Override
public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) {
    RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler();
    if (rejectedExecutionHandler == null) {
        rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
    }
    ScheduledThreadPoolExecutor answer = new RejectableScheduledThreadPoolExecutor(profile.getPoolSize(), threadFactory, rejectedExecutionHandler);
    answer.setRemoveOnCancelPolicy(true);
    // we could potentially keep adding tasks, and run out of memory.
    if (profile.getMaxPoolSize() > 0) {
        return new SizedScheduledExecutorService(answer, profile.getMaxQueueSize());
    } else {
        return answer;
    }
}
Also used : SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) RejectableScheduledThreadPoolExecutor(org.apache.camel.util.concurrent.RejectableScheduledThreadPoolExecutor) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) RejectableScheduledThreadPoolExecutor(org.apache.camel.util.concurrent.RejectableScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) RejectableThreadPoolExecutor(org.apache.camel.util.concurrent.RejectableThreadPoolExecutor) RejectableScheduledThreadPoolExecutor(org.apache.camel.util.concurrent.RejectableScheduledThreadPoolExecutor)

Aggregations

RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 RejectableScheduledThreadPoolExecutor (org.apache.camel.util.concurrent.RejectableScheduledThreadPoolExecutor)1 RejectableThreadPoolExecutor (org.apache.camel.util.concurrent.RejectableThreadPoolExecutor)1 SizedScheduledExecutorService (org.apache.camel.util.concurrent.SizedScheduledExecutorService)1