You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/24 12:14:55 UTC

[3/3] camel git commit: CAMEL-8177: Graceful shutdown - Should allow background thread to terminate

CAMEL-8177: Graceful shutdown - Should allow background thread to terminate


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/44730ce0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/44730ce0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/44730ce0

Branch: refs/heads/camel-2.13.x
Commit: 44730ce0c617d12c1e104c157655217ab5bd930a
Parents: 4dd8545
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 24 11:01:35 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 24 12:14:44 2014 +0100

----------------------------------------------------------------------
 .../org/apache/camel/impl/DefaultExecutorServiceManager.java   | 2 +-
 .../java/org/apache/camel/impl/DefaultShutdownStrategy.java    | 3 ++-
 .../java/org/apache/camel/impl/DefaultThreadPoolFactory.java   | 6 +++---
 .../camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java       | 4 ++--
 4 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/44730ce0/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
index a673382..9565f4a 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
@@ -198,7 +198,7 @@ public class DefaultExecutorServiceManager extends ServiceSupport implements Exe
         ThreadPoolProfile profile = new ThreadPoolProfile(name);
         profile.setPoolSize(poolSize);
         profile.setMaxPoolSize(maxPoolSize);
-        return  newThreadPool(source, name, profile);
+        return newThreadPool(source, name, profile);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/44730ce0/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
index 2d05aea..1663b73 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
@@ -365,7 +365,8 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
 
     private ExecutorService getExecutorService() {
         if (executor == null) {
-            executor = camelContext.getExecutorServiceManager().newSingleThreadExecutor(this, "ShutdownTask");
+            // use a thread pool that allow to terminate idle threads so they do not hang around forever
+            executor = camelContext.getExecutorServiceManager().newThreadPool(this, "ShutdownTask", 0, 1);
         }
         return executor;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/44730ce0/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
index 89eafeb..dd0c639 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
@@ -58,9 +58,9 @@ public class DefaultThreadPoolFactory implements ThreadPoolFactory {
                                          int maxQueueSize, RejectedExecutionHandler rejectedExecutionHandler,
                                          ThreadFactory threadFactory) throws IllegalArgumentException {
 
-        // the core pool size must be higher than 0
-        if (corePoolSize < 1) {
-            throw new IllegalArgumentException("CorePoolSize must be >= 1, was " + corePoolSize);
+        // the core pool size must be 0 or higher
+        if (corePoolSize < 0) {
+            throw new IllegalArgumentException("CorePoolSize must be >= 0, was " + corePoolSize);
         }
 
         // validate max >= core

http://git-wip-us.apache.org/repos/asf/camel/blob/44730ce0/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java b/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java
index 7c79941..9b3ddd7 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java
@@ -40,8 +40,8 @@ public class ThreadsZeroInCoreAndMaxPoolTest extends ContextTestSupport {
                 @Override
                 public void configure() throws Exception {
                     from("direct:start")
-                    // will use a a custom thread pool with 0 in core and 2 max
-                        .threads(0, 2).to("mock:result");
+                    // will use a a custom thread pool with -1 in core and 2 max
+                        .threads(-1, 2).to("mock:result");
                 }
             });
             fail("Expect FailedToCreateRouteException exception here");