title: JmsTemplate does not close connections even with PooledConnectionFactory
body: <p>We use AMQ broker 5.5 and Spring 3.0 for configuring connection factory and other stuffs. 
  The connection factory we are using is PooledConnectionFactory and a part of my config looks like this:</p>
  
  <p>&lt;bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop"&gt;</p>
  
  <p>&nbsp; &lt;property name="connectionFactory"&gt;</p>
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;   &lt;bean class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
        &lt;property name="brokerURL" value="some_url"/&gt;</p>
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;   &lt;/bean&gt;</p>
  
  <p>&nbsp; &lt;/property&gt;</p>
  
  <p>&lt;/bean&gt;</p>
  
  <p>&lt;!-- Spring JMS Template --&gt;</p>
  
  <p>&lt;bean id="jmsTemplate"
  class="org.springframework.jms.core.JmsTemplate"&gt;</p>
  
  <p>&nbsp;&nbsp; &lt;property name="connectionFactory"&gt;
    &lt;ref local="jmsFactory" /&gt;</p>
  
  <p>&nbsp;&nbsp; &lt;/property&gt;</p>
  
  <p>&nbsp;&nbsp; &lt;property name="explicitQosEnabled" value="true"/&gt;</p>
  
  <p>&nbsp;&nbsp; &lt;property name="timeToLive" value="86400000"/&gt;</p>
  
  <p>&lt;/bean</p>
  
  <p>A few days back our broker crashed and kept restarting with this error:</p>
  
  <h1>java.lang.OutOfMemoryError: requested</h1>
  
  <p>369384 bytes for Chunk::new. Out of swap space? </p>
  
  <p>At that point of time, from jconsole, I could not find anything unusual with the broker, except that one of our client application
  which talks with the server (via broker) by sending and listening to messages every <em>minute</em> had created ~3000 connections (saw it on jconsole).
  Once we had shut it down, everything was back to normal. </p>
  
  <p>So, to avoid this I tried closing the connection in finally block doing something like this.</p>
  
  <pre><code>try {
  
     connection = myJmsTemplate.getConnectionFactory().createConnection();
  
     session = connection.createSession(false, 1);
     String messageSelector = "JMSCorrelationID='" + correlationId + "'";
     responseConsumer = session.createConsumer(receiveDestination, messageSelector);
     LOG.info("Starting connection");
     connection.start();
     myJmsTemplate.send(sendDestination, new SimpleTextMessageCreator(
     message, receiveDestination, correlationId));
     LOG.info("Waiting for message with " + messageSelector + " for " + DEFAULT_TIMEOUT + " ms");
     TextMessage responseMessage = (TextMessage) responseConsumer.receive(DEFAULT_TIMEOUT);
  }
  
  catch (Someexception e) {do something}
  finally {
     responseConsumer.close();
     session.close();
     connection.close();
  }
  </code></pre>
  
  <p>But even then I can see the connections floating around in jconsole and are only lost if the client app which publishes the messages is brought down.
  Can someone please help me understand what's happening here and how I can close the connections after each pub sub cycle.</p>
  
  <p>Thank you in advance,</p>
  
  <p>Hari</p>