Search in sources :

Example 6 with SizedScheduledExecutorService

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());
}
Also used : SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService)

Example 7 with SizedScheduledExecutorService

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());
}
Also used : SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService)

Example 8 with SizedScheduledExecutorService

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;
    }
}
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

SizedScheduledExecutorService (org.apache.camel.util.concurrent.SizedScheduledExecutorService)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 ExecutorService (java.util.concurrent.ExecutorService)3 LifecycleStrategy (org.apache.camel.spi.LifecycleStrategy)3 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 NamedNode (org.apache.camel.NamedNode)1 StaticService (org.apache.camel.StaticService)1 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1 ThreadPoolProfile (org.apache.camel.spi.ThreadPoolProfile)1 StopWatch (org.apache.camel.util.StopWatch)1 RejectableScheduledThreadPoolExecutor (org.apache.camel.util.concurrent.RejectableScheduledThreadPoolExecutor)1 RejectableThreadPoolExecutor (org.apache.camel.util.concurrent.RejectableThreadPoolExecutor)1