在消费者端使用PooledConnectionFactory建立与MQ服务器的连接,启动的时候初始化10个消费者。相关代码如下:
protected JMSConnectionUtill(String MQ_LOCATION,String userName,String password) {
this.MQ_LOCATION=MQ_LOCATION;
this.userName=userName;
this.password=password;
// ConnectionFactory :连接工厂,JMS 用它创建连接
ActiveMQConnectionFactory connectionFactory = null;
if(StrKit.notBlank(userName)
&& StrKit.notBlank(password)){
connectionFactory= new ActiveMQConnectionFactory(userName, password, MQ_LOCATION);
} else{
connectionFactory= new ActiveMQConnectionFactory(MQ_LOCATION);
}
pooledConnectionFactory = new PooledConnectionFactory();
pooledConnectionFactory.setConnectionFactory(connectionFactory);
// 设置最大连接数
pooledConnectionFactory.setMaxConnections(100);
// 设置最小
pooledConnectionFactory.setMaximumActiveSessionPerConnection(500);
pooledConnectionFactory.setIdleTimeout(Integer.MAX_VALUE);
}
但是连接总是隔一段时间就完全无征兆的自己关闭了。为此查了很久,都没有找到原因。哪位大神指导如何解决?
怪我咯2017-04-17 16:49:50
Comment out this sentence pooledConnectionFactory.setIdleTimeout(Integer.MAX_VALUE);