简体   繁体   中英

Does it make sense to create same connection object but different session objects

I read this ActiveMQ documentation and got question about creating/using connection and session objects for ActiveMQ, now if I create one connection object which I use among several consumers and each consumer having different session object then would there be any performance difference compared to when I create one connection and one session object? I don't think so. ( don't think from multi-threading issues perspective )

I think if I have one connection object then it doesn't matter whether I have one session object or more than one session object for all consumer because communication will be sequential as I cannot use same connection object while it is doing a communication for any consumer.

I think better approach is to create a pool of connection objects and separate session object for each consumer, like that there would be performance boost?

I think this is true in general as well, like what happens in case of database communication.

This is depends on how many consumers, messages, memory, cpu you have.

The JMS contract is that only 1 session is used by one thread at once - which if you're using consumers means that only 1 consumer can receive messages at once if using the same session

Each consumer must have a session after that if you have many consumers for example 100 it is better to use a PooledConnectionFactory to fix a limit of number of connections to not overhead Ressources.

If you have 10 consumers you can use 1 connection without decreasing performances.

You can do some tests to compare results with your resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM