activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From janylj <>
Subject Sending message using JmsTemplate with PooledConnectionFactory hangs periodically
Date Tue, 30 Sep 2008 00:13:11 GMT

My producer uses Spring's JmsTemplate with PooledConnectionFactory. The
Spring configuration is below. Then I send 10 messages every second. And I
notice that the producer doesn't send message smoothly. Every so often it
would hang for a couple of seconds and then a huge spike of load would come
in. For my application, the prompt response time is important. I am
expecting smooth throughtput rate instead of big up and downs. Any inputs on
the problem? 

  <bean id="pooledJmsFactory"
    <property name="connectionFactory">
    	<ref local="jmsFactory" />
    <property name="maxConnections" value="100"/>   
  <!-- Spring JMS Template -->
  <bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory">
      <ref bean="pooledJmsFactory"/>
    <property name="defaultDestination">
      <ref bean="destination" />

I am also wondering whether the implementation of PooledConnectionFactory is
correct. The reason is that from my profiler, it maxed out 100 connections
very very soon. And default number of sessions on a single connection is
500. The strange thing is that actually there were only 100 session object
in the memory all the time. It doesn't seem that the connection from
PooledConnectionFactory is being re-used, otherwise, the chances are
multiple session objects per connection should exist.

Here is a snippet of code from PooledConnectionFactory. I only see where it
adds new connection to the pool. But I don't see where it get the connection
from the pool other than when removing connection when
pools.size()==maxConnections. Please correct me if I am not understanding

    public synchronized Connection createConnection(String userName, String
password) throws JMSException {
        ConnectionKey key = new ConnectionKey(userName, password);
        LinkedList<ConnectionPool> pools = cache.get(key);

        if (pools == null) {
            pools = new LinkedList<ConnectionPool>();
            cache.put(key, pools);

        ConnectionPool connection = null;
        if (pools.size() == maxConnections) {
            connection = pools.removeFirst();

        // Now.. we might get a connection, but it might be that we need to
        // dump it..
        if (connection != null && connection.expiredCheck()) {
            connection = null;

        if (connection == null) {
            ActiveMQConnection delegate = createConnection(key);
            connection = createConnectionPool(delegate);
        return new PooledConnection(connection);
View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message