As the templates (their default impls) is associated with a CamelContext, we could eventually also add logic, to enlist the template in a list of active template stored on the camel context. So when camel context shutdown, it could shutdown the templates as well - as a fail safe.
And if a client is calling stop on a template manually, we would then need to unregistered it from the list on camel context. To avoid the list to grow large if people create a lot of templates and stop them again. So it would be doable to build-in this "failsafe" for the end users. But ideally its best if users call stop when they no longer need the template. For example if its just a one-stop usage. On Tue, Sep 18, 2012 at 3:26 PM, Claus Ibsen <claus.ib...@gmail.com> wrote: > On Tue, Sep 18, 2012 at 3:12 PM, Christian Schneider > <ch...@die-schneider.net> wrote: >> Hi all, >> >> we had a problem with the camel shutdown at a Talend ESB Camel example after >> updating to camel 2.10-SNAPSHOT. >> >> The example uses a ProducerTemplate with a camel jms producer that is >> injected using an annotation: >> @EndpointInject >> ProducerTemplate producer; >> >> At the end of the example main the spring context and with it the camel >> context is shut down. >> Before the update the update the main then exited normally. After the update >> it did not exit. >> >> I found that the ProducerTemplate created a JMSProducer which with a >> DefaultMessageListenerContainer for the replies. This was still active and >> so the main did not exit. >> When I issues a producer.close(); the main exited normally. >> >> So the question is: Do I need to close a ProducerTemplate myself or should >> it be closed when the camel context that created it is shut down? >> > > Yes its always the clients responsibility to invoke the stop method > when you are done with the template. > See this FAQ: > http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html > > I have polished the javadoc of the createProducerTemplate methods on > CamelContext to make this more clear. > > >> Christian >> >> --- >> Here is the full example: >> https://github.com/Talend/tesb-rt-se/tree/master/examples/camel/jaxrs-jms-http/client >> and the change that made it work again: >> https://github.com/Talend/tesb-rt-se/commit/7a9ae3502ca6f75ff6e38aba9dd94d86578cc028 >> >> >> -- >> Christian Schneider >> http://www.liquid-reality.de >> >> Open Source Architect >> Talend Application Integration Division http://www.talend.com >> > > > > -- > Claus Ibsen > ----------------- > FuseSource > Email: cib...@fusesource.com > Web: http://fusesource.com > Twitter: davsclaus, fusenews > Blog: http://davsclaus.com > Author of Camel in Action: http://www.manning.com/ibsen -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen