懂的淡漠 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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?