Hi Thanks for the advise. In the mean time we have improved the original issue with having prototype scoped @Producer being added as services to close.
This is now fixed on trunk as Camel now detects the scope of the bean and only for singletons will add it as a service to close. For prototypes a WARN log is logged once to remind you to close it yourself. Will look into a solution to have it auto closed as well. On Thu, Apr 15, 2010 at 8:05 PM, matthewm <mmo...@gmail.com> wrote: > > > >> This is a catch-22 situation. When using @Producer or @Consume etc. >> you are creating a Producer/Consumer up front. >> However you also want to stop the @Producer / @Consumer again when you >> are shutting down, or more ideally before if the POJO was no longer in >> use. >> >> However there is no nice API for doing that, so either we could just >> omit the stop and then risk having resources leaked as they are not >> properly stopped. >> >> If you look in the CamelPostProcessorHelper in camel-core in the >> #startService method. >> Its the one which "registers" it in CamelContext (servicesToClose). >> >> We can obviously change that to not do so but just start the service >> with registering. >> But again then we loose the ability to close it. >> >> Any thoughts? >> > > Could you leverage lifecycle callbacks in Spring? > > http://static.springsource.org/spring/docs/3.0.1.RELEASE/reference/html/beans.html#beans-factory-lifecycle-disposablebean > > If @EndpointInject or @Produce create a ProducerTemplate and PT then > registers/starts its Producer(s) with CamelContext.addService, it seems > appropriate that as part of the lifecycle, when the PT's containing bean is > torn down, a destruction callback should be responsible for stopping any > Producers associated with the PT and de-registering them with the > CamelContext. Right now, initialization is automatic but there is no > corresponding de-initialization being done. > > Though this might mean that you need a Spring-specific > DefaultProducerTemplate subclass (or some other Spring-specific > implementation of ProducerTemplate) that is lifecycle-aware, since DPT still > needs to be usable without Spring. > > Matt > > -- > View this message in context: > http://old.nabble.com/Injecting-ProducerTemplates%2C-scoping%2C-and-JMX-memleak-tp28219199p28258673.html > Sent from the Camel - Users mailing list archive at Nabble.com. > > -- Claus Ibsen Apache Camel Committer Author of Camel in Action: http://www.manning.com/ibsen/ Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus