如何在独立的 Java 应用程序中池化 JMS 连接?
我们正在开发一个IBM WebSphere MQ应用程序,我们使用JMS API来操作消息。但是我们有一个问题,连接需要太多时间,并且我们想要池化 JMS 连接,因为它是一个独立的应用程序,我们没有应用程序容器来提供 JNDI 或池化服务。那么有没有办法解决这个问题呢?对于 JDBC,我们可以使用 DBCP 或 c3p0 来归档池数据源,在 JMS 中,是否有类似的项目可以池 JMS 连接?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
过去,JMS MQConnectionFactory 内置了池,但似乎在版本中7、已删除。
如果没有其他任何东西,您可以使用 Apache Commons Pool。与 DBCP(使用 Pool)的想法相同,但适用于非 JDBC 对象。
It used to be that the JMS MQConnectionFactory had pooling built in, but it seems that in version 7, it has been removed.
In the absence of anything else, you can use Apache Commons Pool. Same idea as DBCP (which uses Pool) but for non JDBC objects.
Spring 的 CachingConnectionFactory 非常适合此用例。
https://stackoverflow.com/a/31119435/1765341 中的这个答案解释了如何在 Tomcat 中执行此操作,但是那里的代码可以轻松地适应 Java 独立应用程序。这应该比编写 Apache Commons Pool 实现更容易(并且更不容易出错)。
Spring's CachingConnectionFactory works well for this use case.
This answer in https://stackoverflow.com/a/31119435/1765341 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.