Repository: camel Updated Branches: refs/heads/master 4d6293e55 -> 68457865f
CAMEL-11814: Make no-start flag a global The `no-start` flag being a thread-local variable does not take full effect if there is an attempt to start SpringCamelContext from different threads. Such a condition can occur in Spring tests when due to auto configuration there are two threads competing to start CamelContext: the regular SpringCamelContext/CamelContextFactoryBean reacting to Spring application context startup event; and the CamelMainRunController run from another thread. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/68457865 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/68457865 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/68457865 Branch: refs/heads/master Commit: 68457865f0d097e3b4a659e3c8a0d49f49fa4beb Parents: 4d6293e Author: Zoran Regvart <zregv...@apache.org> Authored: Mon Sep 25 13:00:45 2017 +0200 Committer: Zoran Regvart <zregv...@apache.org> Committed: Tue Sep 26 10:37:17 2017 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/spring/SpringCamelContext.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/68457865/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java index d81ca3d..1134957 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java @@ -16,6 +16,8 @@ */ package org.apache.camel.spring; +import java.util.concurrent.atomic.AtomicBoolean; + import org.apache.camel.Endpoint; import org.apache.camel.component.bean.BeanProcessor; import org.apache.camel.component.event.EventComponent; @@ -60,7 +62,7 @@ public class SpringCamelContext extends DefaultCamelContext implements Lifecycle ApplicationListener<ApplicationEvent>, Ordered { private static final Logger LOG = LoggerFactory.getLogger(SpringCamelContext.class); - private static final ThreadLocal<Boolean> NO_START = new ThreadLocal<Boolean>(); + private static final AtomicBoolean NO_START = new AtomicBoolean(); private ApplicationContext applicationContext; private EventComponent eventComponent; private boolean shutdownEager = true; @@ -73,11 +75,7 @@ public class SpringCamelContext extends DefaultCamelContext implements Lifecycle } public static void setNoStart(boolean b) { - if (b) { - NO_START.set(b); - } else { - NO_START.remove(); - } + NO_START.set(b); } /**