I'm attaching a pretty straightforward example of some code that exhibits a problem that I'm having trouble fixing. I'm hoping someone can either point out my error or at least help me diagnose the problem. Basically, the code simply sends ~5000 messages to a broker. Yes, it's not using a connection pool. That doesn't seem to make any difference and I'm looking for the simplest possible example. After about ~1300 messages, the client runs out of memory and dies (jvm default is 64Mb, iirc).

I've tested this with recent AMQ nightly builds or with 5.0.0.2-fuse and I get the same result in both cases. In running this code, I'm also seeing several exceptions like this (maybe ~10 by the time I get the OOME):

[ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WARN org.apache.activemq.ActiveMQConnection - Async exception with no exception listener: java.net.SocketException: Socket closed

Here's the offending code.  Any help would be super.

phil.

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.log4j.Logger;

public class ActiveMQClientDyingExample {

private static final Logger log = Logger.getLogger (ActiveMQClientDyingExample.class);

        public static void main(final String args[]) {

                final String url = "tcp://localhost:61616";
                final String topicName = "test/foo";

log.debug("Initializing pooled connection factory for JMS to URL: " + url); final ActiveMQConnectionFactory normalFactory = new ActiveMQConnectionFactory();
                normalFactory.setBrokerURL(url);

                for (int i = 0; i < 5000; i++) {
                        
                        if (i % 100 ==0)
                                log.debug(i);

                        Connection conn = null;
                        try {

                                conn = normalFactory.createConnection();
final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
                                final Topic topic = 
session.createTopic(topicName);
                                final MessageProducer producer = 
session.createProducer(topic);
                                
producer.setDeliveryMode(DeliveryMode.PERSISTENT);

                                final MapMessage m = session.createMapMessage();
                                m.setInt("hey", i);

                                producer.send(m);

                        } catch (JMSException e) {
                                log.warn(e.getMessage(), e);
                        } finally {
                                if (conn != null)
                                        try {
                                                conn.close();
                                        } catch (JMSException e) {
                                                log.warn(e.getMessage(), e);
                                        }
                        }

                }
        }

}



--
                                   Whirlycott
                                   Philip Jacob
                                   [EMAIL PROTECTED]
                                   http://www.whirlycott.com/phil/


Reply via email to