Pivotal Knowledge Base


Using Connection Pooling with JMSTemplate in Spring Framework


 Product  Version
 Spring Framework  3.0


This article provides information on using connection pooling with JMSTemplate in Spring Framework. You may want to use connection pooling if you experience a long turnaround time for every JMS message sent.


Without connection pooling, JMSTemplate, by default, creates a new connection, session, producer for each message sent and then closes them all again. This results in a long workaround time and you get reconnected on every JMS message sent.

Connection pooling pools the JMS resources to work efficiently with Spring's JMSTemplate, so that it reuses connections. There are several connection pools available for use in Spring Framework, including SingleConnectionFactory, CachingConnectionPooling, and the provider-specific connection Pooling ActiveMQ's PooledConnectionFactory.

Sample configuration of JMS with ActiveMQ Connection Pooling:

<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">

<property name="connectionFactory">

     <bean class="org.apache.activemq.ActiveMQConnectionFactory">

          <property name="brokerURL">

                 <value> tcp://broker1:61616 </value>





<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" >

< property name="connectionFactory" ref="connectionFactory"/>



Powered by Zendesk