[ https://issues.apache.org/activemq/browse/CAMEL-1509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=50974#action_50974 ]
Marat Bedretdinov commented on CAMEL-1509: ------------------------------------------ The logic in the ServiceSupport is somewhat interesting. The state goes from Thread1 -> ServiceSuppoet.start() -> starting = false and stared = false -> starting = true and started = true -> starting = false and started = true Now why is started = true is set before starting = true? started is in pass tense, so to me this is clearly that started = true should have been set *after* starting went from true to false Moreover there is also a race. Look at the ServiceSupport.stop() method its state goes like this: Thread 1-> ServiceSupport.stop() -> started = true and stopping = false -> stopping = true -> stopped = true and started = false and stopping = false Now lets look at this scenario, 2 threads invoking onto the same CamelContext Thread1 ->ServiceSupport.start() -> starting = false and stared = false -> starting = true and started = true -> @ Thread2-> ServiceSupport.stop() -> started = true and stopping = false -> stopping = true -> @ @ is the point in time when we will have a concurrent start and stop logic executed on the same context and I'd imagine this can't be good ;) > DefaultCamelContext.isStarting returns incorrect status > ------------------------------------------------------- > > Key: CAMEL-1509 > URL: https://issues.apache.org/activemq/browse/CAMEL-1509 > Project: Apache Camel > Issue Type: Bug > Components: camel-core > Affects Versions: 1.6.0, 2.0-M1 > Reporter: Alexander Kleymenov > Assignee: Willem Jiang > > DefaultCamelContext.isStarting returns true while it actually not started. > So the following groovy test case fails: > {code:title=test.groovy} > import org.apache.camel.impl.DefaultCamelContext; > import org.apache.camel.language.groovy.GroovyRouteBuilder; > class Foo { > def name > def data > void run(data) { > println "[${name}] got ${data}" > this.data = data > } > } > public class MyRoute extends GroovyRouteBuilder { > def bean = new Foo(name: "bean") > protected void configure() { > from("direct:start").bean(bean, "run") > } > } > camelCtx = new DefaultCamelContext() > route = new MyRoute() > camelCtx.addRoutes(route); > Thread.start { > camelCtx.start(); > } > while (camelCtx.isStarting()) { > Thread.sleep(1000) > } > camelCtx.createProducerTemplate().sendBody("direct:start", "data") > if (!route.bean.data) { > println "FAILED: no data has been received!" > } else { > println "PASSED" > } > camelCtx.stop(); > {code} > Note, after moving of > {code} > camelCtx.addRoutes(route) > {code} > after > {code} > Thread.start { > camelCtx.start(); > } > {code} > the test passes. > Also the program does not finish after camelCtx.stop(); -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.