How to pool the JMS connection in a standalone Java application?
Asked Answered
H

2

5

We are working on an IBM WebSphere MQ application, and we use JMS API to operate the message. But we have a problem that the connection takes too much time, and we want to pool the JMS connection, for it's a standalone application, we have no application container to provide JNDI or pooling service. So is there a solution to resolve this? For JDBC we can use DBCP or c3p0 to archive pooling datasource, in JMS, is there any similar project that can pool JMS connections?

Hajji answered 19/1, 2012 at 7:17 Comment(0)
A
7

It used to be that the JMS MQConnectionFactory had pooling built in, but it seems that in version 7, it has been removed.

Set the use of ConnectionPooling in earlier versions of the WebSphere MQ classes for JMS. This method is retained for compatibility with older MQJMS applications, but, because this Connection Pooling functionality has been removed from version 7, setting this property will have no effect.

In the absence of anything else, you can use Apache Commons Pool. Same idea as DBCP (which uses Pool) but for non JDBC objects.

Antifebrile answered 19/1, 2012 at 18:57 Comment(2)
Seems Apache Commons Pool is the possible approach for me. Thanks.Hajji
Thanks, I had tried spring CachingConnectionFactory but it was failing. However, seeing as we are using wmq version 6, I will try the native pooling - setUseConnectionPooling(true)Este
J
0

Spring's CachingConnectionFactory works well for this use case. This answer in https://mcmap.net/q/2035593/-websphere-mq-connection-pooling-with-tomcat explains how to do this in Tomcat, but the code there can easily be adapted for Java standalone applications. This should be much easier (and less error prone) than writing an Apache Commons Pool implementation.

Jim answered 29/6, 2015 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.