Search in sources :

Example 6 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.

the class DefaultExecutorServiceStrategyTest method testNewThreadPoolProfile.

public void testNewThreadPoolProfile() throws Exception {
    assertNull(context.getExecutorServiceStrategy().getThreadPoolProfile("foo"));
    ThreadPoolProfileSupport foo = new ThreadPoolProfileSupport("foo");
    foo.setKeepAliveTime(20L);
    foo.setMaxPoolSize(40);
    foo.setPoolSize(5);
    foo.setMaxQueueSize(2000);
    context.getExecutorServiceStrategy().registerThreadPoolProfile(foo);
    ExecutorService pool = context.getExecutorServiceStrategy().newThreadPool(this, "Cool", "foo");
    assertNotNull(pool);
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, pool);
    assertEquals(20, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals(40, tp.getMaximumPoolSize());
    assertEquals(5, tp.getCorePoolSize());
    assertFalse(tp.isShutdown());
    context.stop();
    assertTrue(tp.isShutdown());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 7 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.

the class DefaultExecutorServiceManagerTest method testNewSingleThreadExecutor.

public void testNewSingleThreadExecutor() throws Exception {
    ExecutorService pool = context.getExecutorServiceManager().newSingleThreadExecutor(this, "Cool");
    assertNotNull(pool);
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, pool);
    // a single dont use keep alive
    assertEquals("keepAliveTime", 0, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("maximumPoolSize", 1, tp.getMaximumPoolSize());
    assertEquals(1, tp.getCorePoolSize());
    assertFalse(tp.isShutdown());
    context.stop();
    assertTrue(tp.isShutdown());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 8 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.

the class DefaultExecutorServiceManagerTest method testDefaultUnboundedQueueThreadPool.

public void testDefaultUnboundedQueueThreadPool() throws Exception {
    ThreadPoolProfile custom = new ThreadPoolProfile("custom");
    custom.setPoolSize(10);
    custom.setMaxPoolSize(30);
    custom.setKeepAliveTime(50L);
    custom.setMaxQueueSize(Integer.MAX_VALUE);
    context.getExecutorServiceManager().setDefaultThreadPoolProfile(custom);
    assertEquals(true, custom.isDefaultProfile().booleanValue());
    ExecutorService myPool = context.getExecutorServiceManager().newDefaultThreadPool(this, "myPool");
    assertEquals(false, myPool.isShutdown());
    // should use default settings
    ThreadPoolExecutor executor = (ThreadPoolExecutor) myPool;
    assertEquals(10, executor.getCorePoolSize());
    assertEquals(30, executor.getMaximumPoolSize());
    assertEquals(50, executor.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals(Integer.MAX_VALUE, executor.getQueue().remainingCapacity());
    context.stop();
    assertEquals(true, myPool.isShutdown());
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 9 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.

the class DefaultExecutorServiceManagerTest method testGetThreadPoolProfileInheritCustomDefaultValues2.

public void testGetThreadPoolProfileInheritCustomDefaultValues2() throws Exception {
    ThreadPoolProfile newDefault = new ThreadPoolProfile("newDefault");
    // just change the max pool as the default profile should then inherit the old default profile
    newDefault.setMaxPoolSize(50);
    context.getExecutorServiceManager().setDefaultThreadPoolProfile(newDefault);
    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setPoolSize(1);
    context.getExecutorServiceManager().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(1, tp.getCorePoolSize());
    // should inherit the default values
    assertEquals(50, tp.getMaximumPoolSize());
    assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("CallerRuns", tp.getRejectedExecutionHandler().toString());
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 10 with ThreadPoolExecutor

use of java.util.concurrent.ThreadPoolExecutor in project camel by apache.

the class DefaultExecutorServiceManagerTest method testCustomDefaultThreadPool.

public void testCustomDefaultThreadPool() throws Exception {
    ThreadPoolProfile custom = new ThreadPoolProfile("custom");
    custom.setKeepAliveTime(20L);
    custom.setMaxPoolSize(40);
    custom.setPoolSize(5);
    custom.setMaxQueueSize(2000);
    context.getExecutorServiceManager().setDefaultThreadPoolProfile(custom);
    assertEquals(true, custom.isDefaultProfile().booleanValue());
    ExecutorService myPool = context.getExecutorServiceManager().newDefaultThreadPool(this, "myPool");
    assertEquals(false, myPool.isShutdown());
    // should use default settings
    ThreadPoolExecutor executor = (ThreadPoolExecutor) myPool;
    assertEquals(5, executor.getCorePoolSize());
    assertEquals(40, executor.getMaximumPoolSize());
    assertEquals(20, executor.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals(2000, executor.getQueue().remainingCapacity());
    context.stop();
    assertEquals(true, myPool.isShutdown());
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) ExecutorService(java.util.concurrent.ExecutorService) SizedScheduledExecutorService(org.apache.camel.util.concurrent.SizedScheduledExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)397 Test (org.junit.Test)79 ExecutorService (java.util.concurrent.ExecutorService)74 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)60 ThreadFactory (java.util.concurrent.ThreadFactory)38 ArrayList (java.util.ArrayList)34 IOException (java.io.IOException)33 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)30 SynchronousQueue (java.util.concurrent.SynchronousQueue)29 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)22 ExecutionException (java.util.concurrent.ExecutionException)21 Future (java.util.concurrent.Future)20 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)18 CountDownLatch (java.util.concurrent.CountDownLatch)18 Test (org.testng.annotations.Test)18 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)16 SizedScheduledExecutorService (org.apache.camel.util.concurrent.SizedScheduledExecutorService)16 HashMap (java.util.HashMap)14