activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Makarenko <l...@softline.kiev.ua>
Subject Re: ActiveMQ 4.x memory leak in multithreaded applications
Date Tue, 22 Aug 2006 10:13:23 GMT

Thanx for advice.


James.Strachan wrote:
> 
> As I said, I've fixed a bug in PooledConnectionFactory that was not
> garbage collecting consumers created.
> 
> Though note that there is no real gain using the
> PooledConnectionFactory when using consumers as consumers are not
> pooled.
> 
> 
> On 8/21/06, Alex Makarenko <lazy@softline.kiev.ua> wrote:
>>
>> I am using org.activemq.pool.PooledConnectionFactory, as recomended in
>> Spring
>> guide.
>> But again even without JmsTemplate (clean JMS API) MessageConsumers are
>> never released by ActiveMQ
>>
>>         private void receive() throws JMSException {
>>             Connection conn = null;
>>             Session sess = null;
>>             MessageConsumer consumer = null;
>>             try {
>>                 Message message = null;
>>                 if(useSpring)
>>                     message = jmsTemplate.receive();
>>                 else {
>>                     conn = factory.createConnection();
>>                     sess = conn.createSession(true,
>> Session.SESSION_TRANSACTED);
>>                     consumer =
>> sess.createConsumer(jmsTemplate.getDefaultDestination());
>>                     message =
>> consumer.receive(jmsTemplate.getReceiveTimeout());
>>                 }
>>
>>
>>                 if(message instanceof ObjectMessage) {
>>                     //System.out.println("c: Received message: \"" +
>> ((TextMessage)message).getText() +"\"");
>>                 }
>>                 sess.commit();
>>             } finally {
>>                 if(!useSpring) {
>>                     if(consumer != null)
>>                         consumer.close();
>>                     if(sess != null)
>>                         sess.close();
>>                     if(conn != null)
>>                         conn.close();
>>                 }
>>
>>             }
>>         }
>>
>>
>> James.Strachan wrote:
>> >
>> > Note that using JmsTemplate without some pooling is a very inefficient
>> > way of working with JMS. JmsTemplate is generally not recommended for
>> > consuming messages. The PooledConnectionFactory only pools for sending
>> > messages - not consuming them. To consume messages with pooled I'd
>> > recommend you either use Spring 2's consumer containers or Jencks.
>> >
>> > http://incubator.apache.org/activemq/jmstemplate-gotchas.html
>> > http://incubator.apache.org/activemq/how-do-i-use-jms-efficiently.html
>> >
>> >
>> > On 8/19/06, Alex Makarenko <lazy@softline.kiev.ua> wrote:
>> >>
>> >> Hello everyone!
>> >> I discovered some strange behavior of ActiveMQ 4.x in terms of
>> >> MessageConsumer handling. It seamed that ActiveMQ 4.x versions in some
>> >> cases
>> >> do not release MessageConsumers while versions 3.2.x do.
>> >> I have application that must work with limited system resources such
>> as
>> >> number of threads and number of simultaneously running tasks on
>> message
>> >> processing. A cannot use asynchronous message processing instead I
>> have
>> >> to
>> >> use thread pool with 3 threads. Every thread creates MessageConsumer
>> and
>> >> tries to process message in case of failures massage is rolled back to
>> >> queue. MessageConsumers are created to support independant
>> transactions
>> >> for
>> >> every thread.
>> >> Initially I was using ActiveMQ 4.0.1   Spring's JmsTemplate and
>> >> TransactionTemplate. But after day or two of work I've got
>> >> OutOfMemoryError.
>> >> I tried to dig what's going on with YourKit Java Profiler and
>> discovered
>> >> that ActiveMQMessageConsumer objects that was created with JmsTemplate
>> in
>> >> each thread are still in memory and never get garbage collected. I
>> >> thought
>> >> it's a Spring bug but when I rewrote application to use clean JMS the
>> >> situation do not changed.
>> >> I am attaching screen shots from YourKit Java Profiler with Spring and
>> >> without; along with sample application. It seams that ActiveMQ leaks
>> >> MessageConsumers. Again it does not happen with versions 3.2.2.
>> >>
>> >> http://gis.softline.kiev.ua/sample.zip sample application
>> >>
>> >> Profiler results on application with Spring
>> >>
>> >   http://gis.softline.kiev.ua/profiler_1.gif
>> >> Profiler results on application without Spring
>> >>
>> >   http://gis.softline.kiev.ua/profiler_2.gif
>> >
>> > I think I've fixed the bug in SVN trunk if you want to try tomorrows
>> > 4.1-SNAPSHOT build it should now be resolved.
>> >
>> > --
>> >
>> > James
>> > -------
>> > http://radio.weblogs.com/0112098/
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/ActiveMQ-4.x-memory-leak-in-multithreaded-applications-tf2131839.html#a5905493
>> Sent from the ActiveMQ - User forum at Nabble.com.
>>
>>
> 
> 
> -- 
> 
> James
> -------
> http://radio.weblogs.com/0112098/
> 
> 

-- 
View this message in context: http://www.nabble.com/ActiveMQ-4.x-memory-leak-in-multithreaded-applications-tf2131839.html#a5922710
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message