一个Java生产者使用spring连接池来管理100个MQ连接。 每个MQ连接默认可以打开500个会话。
产生50000条消息后,将使用所有连接和会话。
从spring连接池中获得一个新的连接将非常慢(首先从该池中获得一个连接,然后创建一个新的会话)。
而且关闭连接将需要很长时间。
而且ActiveMQ服务器将使用大量内存。
我想知道:
如何删除或重用连接创建的会话?
何时关闭MQ连接?
我尝试了以下参数:idleTimeout + expiryTimeout + timeBetweenExpirationCheckMillis,但是:
当系统很忙很长时间。 整个系统将越来越慢。 ActiveMQ将使用越来越多的内存。
当系统很忙时,然后突然变得空闲,然后突然很忙。 timeBetweenExpirationCheckMillis不够快,无法关闭所有连接。 连接池将尝试关闭所有超时连接(idleTimeout或expiryTimeout),然后打开一个新连接。 整个系统将停留10-20分钟。
我试图禁用kahadb持久性,但不起作用。
Update1:ActiveMQ连接池配置
Update2:测试代码
package just.a.test;
import javax.jms.Destination;
import net.sf.json.JSONObject;
import org.springframework.jms.core.JmsTemplate;
@Component
public final class TestHandlerImpl{
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Destination testQueue;
public void sendMessage(File binaryFile){
//read file, get one msg
JSONObject msg = processBinaryFile(binaryFile);
//send msg to queue
sendMessageToQueue(testQueue, msg.toString());
}
}
protected void sendMessageToQueue(Destination destination, final String msg) {
//this code will get one connection from pool
//create a new session
//and send the message
jmsTemplate.send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(msg);
}
});
}
}
UPDATE3:
现在,我必须修改activemq-all.jar和common-pool.jar以使整个系统稳定。 我认为这是不对的。