首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

JmsTemplate 集成activemq中 connection 与 session的治理

2014-01-15 
JmsTemplate 集成activemq中 connection 与 session的管理1.PooledConnectionFactory中有段代码(1) this.c

JmsTemplate 集成activemq中 connection 与 session的管理
1.PooledConnectionFactory中有段代码
(1) this.connectionsPool.setMaxIdle(1);
     保证connectionPool只反回同一个连接

(2)
   try {
            connection = connectionsPool.borrowObject(key);
        } catch (Exception e) {
            throw JMSExceptionSupport.create("Error while attempting to retrieve a connection from the pool", e);
        }

        try {
            connectionsPool.returnObject(key, connection);
        } catch (Exception e) {
            throw JMSExceptionSupport.create("Error when returning connection to the pool", e);
        }

      连接borrow出去时,立即return归还。
     这样每个次发送,jmsTemplate.send ....方法,使终获取的同一个连接。

2.ConnectionPool中的
public Session createSession(boolean transacted, int ackMode) throws JMSException {
        SessionKey key = new SessionKey(transacted, ackMode);
        PooledSession session;
        try {
            session = sessionPool.borrowObject(key);
        } catch (Exception e) {
            throw JMSExceptionSupport.create(e);
        }
        return session;
    }

在哪里归还的呢?是在PooledSession的close方法进行归还

3.注意在browsConnection时执行validateObject方法
中的connection.expiredCheck()。
过期时 sessionPool.close();

所以每session中如果没有过期的话,
这样每个次发送,jmsTemplate.send ....方法,使终获取的同一个连接且同一个session

热点排行