James, great answer

Please add a FAQ entry about this ;)


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED] 
Sent: 18. september 2008 10:52
To: [email protected]
Subject: [SPAM] Re: ProducerTemplate and ActiveMQ component seems to leak 
threads

2008/9/17 jayson.minard <[EMAIL PROTECTED]>:
>
> With a route such as:
>
>
>    from("activemq:queue:test.input").process(new
> TestProcessor("activemq:queue:test.output"));
>
>
> And in the TestProcessor class, if we do something like:
>
>
>    // outEndPoint is derived from the constructor parameter and is
> "activemq:queue:test.output.something"
>    Message msg = exchange.getIn();
>    ProducerTemplate producer =
> exchange.getContext().createProducerTemplate();
>    producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
> msg.getHeaders());
>
>
> It leaks threads and holds open ActiveMQ sessions endlessly.

You are not meant to create a ProducerTemplate for each message
invocation; you are meant to create a single instance on startup and
keep it around.  Also when you have finished using the
ProducerTemplate you should call the stop() method to close down all
the resources it has been using.

Its better to either explicitly create one on startup or get your IoC
container (Spring/Guice) to inject it into your Processor

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Reply via email to