Author: davsclaus
Date: Mon Oct 22 10:04:15 2012
New Revision: 1400823

URL: http://svn.apache.org/viewvc?rev=1400823&view=rev
Log:
CAMEL-5725: Thread pool profile - maxQueueSize = 0 should mean no work queue in 
use

Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java?rev=1400823&r1=1400822&r2=1400823&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
 Mon Oct 22 10:04:15 2012
@@ -58,10 +58,9 @@ public class DefaultThreadPoolFactory im
                                          int maxQueueSize, 
RejectedExecutionHandler rejectedExecutionHandler,
                                          ThreadFactory threadFactory) throws 
IllegalArgumentException {
 
-        // If we set the corePoolSize to be 0, the whole camel application 
will hang in JDK5
-        // just add a check here to throw the IllegalArgumentException
+        // the core pool size must be higher than 0
         if (corePoolSize < 1) {
-            throw new IllegalArgumentException("The corePoolSize can't be 
lower than 1");
+            throw new IllegalArgumentException("CorePoolSize must be >= 1, was 
" + corePoolSize);
         }
 
         // validate max >= core
@@ -71,16 +70,16 @@ public class DefaultThreadPoolFactory im
 
         BlockingQueue<Runnable> workQueue;
         if (corePoolSize == 0 && maxQueueSize <= 0) {
-            // use a synchronous queue
+            // use a synchronous queue for direct-handover (no tasks stored on 
the queue)
             workQueue = new SynchronousQueue<Runnable>();
             // and force 1 as pool size to be able to create the thread pool 
by the JDK
             corePoolSize = 1;
             maxPoolSize = 1;
         } else if (maxQueueSize <= 0) {
-            // unbounded task queue
-            workQueue = new LinkedBlockingQueue<Runnable>();
+            // use a synchronous queue for direct-handover (no tasks stored on 
the queue)
+            workQueue = new SynchronousQueue<Runnable>();
         } else {
-            // bounded task queue
+            // bounded task queue to store tasks on the queue
             workQueue = new LinkedBlockingQueue<Runnable>(maxQueueSize);
         }
 

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java?rev=1400823&r1=1400822&r2=1400823&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
 Mon Oct 22 10:04:15 2012
@@ -141,7 +141,7 @@ public class DefaultExecutorServiceManag
         custom.setPoolSize(10);
         custom.setMaxPoolSize(30);
         custom.setKeepAliveTime(50L);
-        custom.setMaxQueueSize(-1);
+        custom.setMaxQueueSize(Integer.MAX_VALUE);
 
         
context.getExecutorServiceManager().setDefaultThreadPoolProfile(custom);
         assertEquals(true, custom.isDefaultProfile().booleanValue());
@@ -160,6 +160,30 @@ public class DefaultExecutorServiceManag
         assertEquals(true, myPool.isShutdown());
     }
 
+    public void testDefaultNoMaxQueueThreadPool() throws Exception {
+        ThreadPoolProfile custom = new ThreadPoolProfile("custom");
+        custom.setPoolSize(10);
+        custom.setMaxPoolSize(30);
+        custom.setKeepAliveTime(50L);
+        custom.setMaxQueueSize(0);
+
+        
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(0, executor.getQueue().remainingCapacity());
+
+        context.stop();
+        assertEquals(true, myPool.isShutdown());
+    }
+
     public void testCustomDefaultThreadPool() throws Exception {
         ThreadPoolProfile custom = new ThreadPoolProfile("custom");
         custom.setKeepAliveTime(20L);

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java?rev=1400823&r1=1400822&r2=1400823&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java
 Mon Oct 22 10:04:15 2012
@@ -142,7 +142,7 @@ public class DefaultExecutorServiceStrat
         custom.setPoolSize(10);
         custom.setMaxPoolSize(30);
         custom.setKeepAliveTime(50L);
-        custom.setMaxQueueSize(-1);
+        custom.setMaxQueueSize(Integer.MAX_VALUE);
 
         
context.getExecutorServiceStrategy().setDefaultThreadPoolProfile(custom);
         assertEquals(true, custom.isDefaultProfile().booleanValue());


Reply via email to