camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: Injecting ProducerTemplates, scoping, and JMX memleak
Date Tue, 13 Apr 2010 07:15:42 GMT
On Tue, Apr 13, 2010 at 1:22 AM, matthewm <> wrote:
> Hello,
> We are using Camel 2.2.0 with Spring 3.0.1.RELEASE in the context of a web
> service.
> We've been using @EndpointInject to inject ProducerTemplates into our beans.
> Some of our beans are request scoped, and so a new ProducerTemplate is
> created and injected on each request.
> After more study this seems to run counter to the idea of ProducerTemplate,
> which appears to have been conceived as a long-lived object rather than
> transient.  It seems perhaps the documentation of @EndpointInject might
> point this out; injecting into singletons makes perfect sense but injecting
> into request-scoped beans may be undesirable.

The FAQ has some details on producer template

You can just use @Autowired or other Spring IoC stuff.

private ProducerTemplate template;

Camel will automatic enlist a ProducerTemplate if you do not explict
set a <template id="xxx"/> in the <camelContext/> tag.
Then it will use the shared instance of ProducerTemplate instead of
creating a new one each time.

> Specifically, the issue we found is that each ProducerTemplate creates a
> Producer which then is registered with JMX.  Eventually we wind up with
> thousands of Producers referenced by JMX (but otherwise garbage) resulting
> in OOM errors.

Yeah this is fixed in 2.3-SNAPSHOT.

> It seems like a bug that Camel's JMX integration prevents producers from
> being eligible for GC.  But how best to proceed with making a
> ProducerTemplate available to request scoped beans?
> Thanks!
> Matt
> --
> View this message in context:
> Sent from the Camel - Users mailing list archive at

Claus Ibsen
Apache Camel Committer

Author of Camel in Action:
Open Source Integration:

View raw message