You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Aidan <ai...@thalesgroup.com.au> on 2008/04/18 07:26:39 UTC

What is best practice for creating Producers?

Hi,

I am using ActiveMQ 5 and am having an issue with my server (running
embedded broker) hitting a deadlock with in MemoryUsage.waitForMemory. I
have read the JIRA defects for this, however I have a question about how I
am using Producers in ActiveMQ (the file-system Cursor seems like it would
work nicely, but appears to only be configurable from the XML files, whereas
I use ActiveMQ and programatically configure it).

Each time I want to send a message to the server from my client I create a
new Producer, send the message and close the producer. One of my co-workers
said that he thinks that this sounds like an anti-pattern. After using
JProfiler and seeing how many ProducerId objects are created (and don't
appear to be garbage collected).

So my question is: Should I be creating one producer per queue/topic and
re-using it, or am I able to create one-per-request?

Cheers,

Aidan
-- 
View this message in context: http://www.nabble.com/What-is-best-practice-for-creating-Producers--tp16760359s2354p16760359.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: What is best practice for creating Producers?

Posted by James Strachan <ja...@gmail.com>.
BTW there's a FAQ entry about this...
http://activemq.apache.org/how-do-i-use-jms-efficiently.html

On 18/04/2008, Rob Davies <ra...@gmail.com> wrote:
>
>  On 18 Apr 2008, at 06:26, Aidan wrote:
>
>
> >
> > Hi,
> >
> > I am using ActiveMQ 5 and am having an issue with my server (running
> > embedded broker) hitting a deadlock with in MemoryUsage.waitForMemory. I
> > have read the JIRA defects for this, however I have a question about how I
> > am using Producers in ActiveMQ (the file-system Cursor seems like it would
> > work nicely, but appears to only be configurable from the XML files,
> whereas
> > I use ActiveMQ and programatically configure it).
> >
> > Each time I want to send a message to the server from my client I create a
> > new Producer, send the message and close the producer. One of my
> co-workers
> > said that he thinks that this sounds like an anti-pattern. After using
> > JProfiler and seeing how many ProducerId objects are created (and don't
> > appear to be garbage collected).
> >
> > So my question is: Should I be creating one producer per queue/topic and
> > re-using it, or am I able to create one-per-request?
> >
> > Cheers,
> >
> > Aidan
> > --
> > View this message in context:
> http://www.nabble.com/What-is-best-practice-for-creating-Producers--tp16760359s2354p16760359.html
> > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >
> >
>
>  Say thanks to your co-worker! It is an anti-pattern.
>
>   Please re-use your producers  - you don't even need one per destination -
> create a Producer with a null Destination - e.g.
>
>  Message producer = session.createProducer(null)
>
>
>
>
>  cheers,
>
>  Rob
>
>  http://open.iona.com/ -Enterprise Open Integration
>  http://rajdavies.blogspot.com/
>
>
>
>


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

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

Re: What is best practice for creating Producers?

Posted by Aidan <ai...@thalesgroup.com.au>.
Thanks Rob for your reply. We were discussing the problem today over coffee,
and I suppose I had always used it in a fashion similar to a JDBC
connection.

I have changed my code to use a single producer for all sending, however on
the server over time I still notice that the memory statistics seem to grow
(in the MemoryUsage  log statements) and don't seem to go down, even when I
turn clients off.

I should explain a little more about my application, it's a thick client (so
it isn't running inside an application server) and the messages will be
arriving in bursts while a user is using the application, but the
application may not be fired up for several days/weeks. I have had to
disable the inactivity timer for the TCP connections as I can't seem to get
the queues and topics to work correctly once the inactivity monitor has
closed the connections.

Is there any way I can get the ActiveMQ internals to release resources once
a client has disconnected? The memory usage seems to grow to around 100 and
then will stop accepting any further messages. 

Thankyou for your help!

Aidan
-- 
View this message in context: http://www.nabble.com/What-is-best-practice-for-creating-Producers--tp16760359s2354p16763388.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: What is best practice for creating Producers?

Posted by Rob Davies <ra...@gmail.com>.
On 18 Apr 2008, at 06:26, Aidan wrote:

>
> Hi,
>
> I am using ActiveMQ 5 and am having an issue with my server (running
> embedded broker) hitting a deadlock with in  
> MemoryUsage.waitForMemory. I
> have read the JIRA defects for this, however I have a question about  
> how I
> am using Producers in ActiveMQ (the file-system Cursor seems like it  
> would
> work nicely, but appears to only be configurable from the XML files,  
> whereas
> I use ActiveMQ and programatically configure it).
>
> Each time I want to send a message to the server from my client I  
> create a
> new Producer, send the message and close the producer. One of my co- 
> workers
> said that he thinks that this sounds like an anti-pattern. After using
> JProfiler and seeing how many ProducerId objects are created (and  
> don't
> appear to be garbage collected).
>
> So my question is: Should I be creating one producer per queue/topic  
> and
> re-using it, or am I able to create one-per-request?
>
> Cheers,
>
> Aidan
> -- 
> View this message in context: http://www.nabble.com/What-is-best-practice-for-creating-Producers--tp16760359s2354p16760359.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Say thanks to your co-worker! It is an anti-pattern.

  Please re-use your producers  - you don't even need one per  
destination - create a Producer with a null Destination - e.g.

Message producer = session.createProducer(null)




cheers,

Rob

http://open.iona.com/ -Enterprise Open Integration
http://rajdavies.blogspot.com/