2 fymdchenwei fymdchenwei 于 2014.08.02 11:25 提问

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不甚了解,大家有没有解决方案,谢谢。

Csdn user default icon
上传中...
上传图片
插入图片