懂的淡漠 2014-08-01 19:25 采纳率: 0%
浏览 1794

WMQ7.x 使用JMS如何建立连接池

现在使用WMQ7.1版本,使用JMS测试发送效率,简单代码如下:

//初始化方法

public void init() {
    mqConnectionFactory = new MQConnectionFactory();
    try {
        mqConnectionFactory.setQueueManager(this.queueManager);
        mqConnectionFactory.setChannel(this.channel);
        mqConnectionFactory.setHostName(this.hostname);
        mqConnectionFactory.setCCSID(this.ccsid);
        mqConnectionFactory.setPort(this.port);
        mqConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);                    
    } catch (JMSException e) {
        e.printStackTrace();
    }
}

//send方法

public void send(String queue, String msg) {
try {

    connection = this.mqConnectionFactory.createConnection(
    this.userName, this.password);        session = connection.createSession(Boolean.FALSE,
            Session.AUTO_ACKNOWLEDGE);
    MQQueue sendQueue = new MQQueue(queue);
    sendQueue.setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
    sendQueue.setCCSID(this.ccsid);

    producer = session.createProducer(sendQueue);

        TextMessage message = session.createTextMessage();
        message.setText(msg);
        producer.send(message);
        producer.close();
        this.session.close();
    } catch (JMSException e) {
        e.printStackTrace();
    }

}

现在如果按上面的代码测试:

for(int i=0;i<10000;i++){

send("test",msg)

}

由于没有连接池,每次都需要创建-关闭connection,session,producer,效率会很低。

WMQ7.1我查询了最新的MQConnectionFactoryAPI,​

setUseConnectionPooling

@Deprecated

public void setUseConnectionPooling( boolean usePooling)

Deprecated. JMS does not use connection pooling anymore. Any connection pooling should be done using the facilities provided by the App Server.

  • 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.

Parameters:

usePooling - true sets the useConnectionPooling property.

该方法已经失效了,Any connection pooling should be done using the facilities provided by the App Server.由于刚接触WMQ不甚了解,大家有没有解决方案,谢谢。

展开全部

  • 写回答

0条回答 默认 最新

      编辑
      预览

      报告相同问题?

      手机看
      程序员都在用的中文IT技术交流社区

      程序员都在用的中文IT技术交流社区

      专业的中文 IT 技术社区,与千万技术人共成长

      专业的中文 IT 技术社区,与千万技术人共成长

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      客服 返回
      顶部