activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Topher Johnson <>
Subject Memory Leak in ActiveMQConnection/ActiveMQConnectionFactory when broker is down
Date Fri, 01 Jun 2007 18:55:35 GMT

When we attempt to create a connection and our broker is down, we
continuously attempt to reconnect.  This causes repeated calls to
createActiveMQConnection in the ActiveMQConnectionFactory class, which in
turn creates a new ActiveMQConnection object.   

The constructor of this object adds a reference of itself to a collection
called factoryStats.  When the exception is thrown because the broker cannot
be found the reference to the connection object in the factoryStats object
is not removed which causes a memory leak.  

Our fix for this was to add some lines to the catch blocks in the
createActiveMQConnection(String, String) method in ActiveMQConnectionFactory
that will remove the reference to the connection object from the
factoryStats object (Our additions/changes are in bold):


protected ActiveMQConnection createActiveMQConnection(String userName,
String password) throws JMSException {
        if (brokerURL == null) {
            throw new ConfigurationException("brokerURL not set.");
        Transport transport;
        ActiveMQConnection connection = null;
        try {
            transport = createTransport();
            connection = createActiveMQConnection(transport, factoryStats);



            if( clientID !=null )

            return connection;
        catch (JMSException e) {
            if(factoryStats != null)
            throw e;
        catch (Exception e) {
             if(factoryStats != null)
             throw JMSExceptionSupport.create("Could not connect to broker
URL: " + brokerURL + ". Reason: " + e, e);
View this message in context:
Sent from the ActiveMQ - Dev mailing list archive at

View raw message