Active PooledConnectionFactory pooling Connections

2019-05-19 01:53发布

I'm looking at using PooledConnectionFactory in a Tomcat application, where in a Tomcat POST handler I want to drop a message into a queue to be picked up by a single remote consumer. AMQ pools both Connection and Session objects, and I'm trying to understand when I should use one over the other.

The approach I'm considering is to have a single Connection and set MaximumActiveSessionPerConnection to match my Tomcat threads, and the POST handler would borrow and return Sessions from the connection. Does this sound reasonable, or are there are advantages to pooling Connections instead?

If it matters, I'm not using Spring or other web app frameworks, just Tomcat. I'm persisting messages to disk in AMQ.

标签: java activemq
1条回答
可以哭但决不认输i
2楼-- · 2019-05-19 02:35

Both approaches should be functionally equivalent, and the difference in the code to do one vs. the other should be relatively small.

In terms of performance I don't think it will really matter as your bottleneck will be on the consuming side not on the producing side since you have a single consumer and potentially many concurrent producers.

Personally, I would prefer letting the pool do all the work and just writing the application as if it is creating a connection and session every time it sends a message (which would obviously be a huge anti-pattern without a pool).

查看更多
登录 后发表回答