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 阅读更多
(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 阅读更多
相关文章推荐
- ActiveMQ使用spring JmsTemplate发送消息(一)
- SpringMVC集成Spring-Session进行分布式管理
- SSH集成中对Session的管理
- ActiveMQ——6.Spring-JmsTemplate特性设置
- springboot 整合 activemq,JmsMessagingTemplate注入失败
- ActiveMQ使用spring JmsTemplate发送消息(一)
- activemq5.14.5+spring-jms3.2.18+maven集成 + jaas权限认证
- Spring3 JmsTemplate与MQ的集成
- ActiveMQ使用spring JmsTemplate发送消息(一)
- hibernate,spring管理事务中(transaction,JDBC connection,Hibernate Session的使用)
- ActiveMQ——4.Spring-JmsTemplate之发送与接收
- jms activeMQ与spring的集成
- activeMQ,spring的jmstemplate简单例子
- ActiveMQ使用spring JmsTemplate发送消息(一)
- 【ActiveMQ】Spring Jms集成ActiveMQ学习记录
- ActiveMQ使用spring JmsTemplate发送消息(一)
- ActiveMQ使用spring JmsTemplate发送消息(一)
- 1.异步消息Jms及其JmsTemplate的源代码分析,消息代理ActiveMQ
- JMS-PooledConnectionFactory(activemq-pool)
- ActiveMQ——activemq的报错见解javax.jms.JMSException: Software caused connection abort: recv failed