简体   繁体   中英

JMS connection & session pooling

I am currently working on a product which has its own JMS provider whose implementation is not well documented. I have to prepare a stand alone client application in Java that will post messages to the JMS queue. I am expecting a huge data volume and hence I am thinking about implementing a JMS connection pool and session pool.

In any object pool, we need to determine if the object is healthy before returning it to the client. JMS does not seem to provide an "isHealthy()" method. Also, I am not able to rely on the ExceptionListener mainly because I am not sure about the JMS provider implementation and also ExceptionListener call is asynchronous. I wonder what will happen if the connection is handed over to the client before the onException is invoked.

As a solution, I am planning to use the TCP idle connection timeout. My understanding is, a connection will become unhealthy only if the TCP idle time connection timeout is over or if the JMS provider is down.

Hence I am planning to create a pooled Connection wrapper object which will store a "last use time" when the connection is created or is returned to the pool by the client. Before handing over the connection to the client, the pool will check if the time interval since the "last use time" is less than 3 minutes (assuming default TCP idle connection timeout is 5 minutes).

Is my understanding and implementation correct?

Here is what I would do:

If this fail, then my connection is dead. GenericObjectPool would then automatically invoke the factory to create a brand new connection ( #makeObject ) to replace the dead one.

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