懂的淡漠 2014-08-02 03:25 采纳率: 0%
浏览 1793

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条回答

    报告相同问题?

    悬赏问题

    • ¥15 matlab实现基于主成分变换的图像融合。
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊