use of org.apache.camel.util.concurrent.SizedScheduledExecutorService in project camel by apache.
the class DefaultExecutorServiceManagerTest method testNewScheduledThreadPoolProfileById.
public void testNewScheduledThreadPoolProfileById() throws Exception {
assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
ThreadPoolProfile foo = new ThreadPoolProfile("foo");
foo.setKeepAliveTime(20L);
foo.setMaxPoolSize(40);
foo.setPoolSize(5);
foo.setMaxQueueSize(2000);
context.getExecutorServiceManager().registerThreadPoolProfile(foo);
ExecutorService pool = context.getExecutorServiceManager().newScheduledThreadPool(this, "Cool", "foo");
assertNotNull(pool);
SizedScheduledExecutorService tp = assertIsInstanceOf(SizedScheduledExecutorService.class, pool);
// a scheduled dont use keep alive
assertEquals(0, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(Integer.MAX_VALUE, tp.getMaximumPoolSize());
assertEquals(5, tp.getCorePoolSize());
assertFalse(tp.isShutdown());
context.stop();
assertTrue(tp.isShutdown());
}
use of org.apache.camel.util.concurrent.SizedScheduledExecutorService in project camel by apache.
the class DefaultExecutorServiceManagerTest method testNewScheduledThreadPool.
public void testNewScheduledThreadPool() throws Exception {
ExecutorService pool = context.getExecutorServiceManager().newScheduledThreadPool(this, "Cool", 5);
assertNotNull(pool);
SizedScheduledExecutorService tp = assertIsInstanceOf(SizedScheduledExecutorService.class, pool);
// a scheduled dont use keep alive
assertEquals(0, tp.getKeepAliveTime(TimeUnit.SECONDS));
assertEquals(Integer.MAX_VALUE, tp.getMaximumPoolSize());
assertEquals(5, tp.getCorePoolSize());
assertFalse(tp.isShutdown());
context.stop();
assertTrue(tp.isShutdown());
}
use of org.apache.camel.util.concurrent.SizedScheduledExecutorService 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;
}
}
Aggregations