您的位置:首页 > 其它

JmsTemplate 集成activemq中 connection 与 session的管理

2014-01-13 15:36 309 查看
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 阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: