2 hangejnu hangejnu 于 2014.01.14 11:29 提问

JMS 创建连接超时时间设置

如下,我用jms创建了一个连接

Connection connection = null;
    JmsFactoryFactory ff;
    try {
        ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
        JmsConnectionFactory cf = ff.createConnectionFactory();
        // Set the properties
        cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, host);
        cf.setIntProperty(WMQConstants.WMQ_PORT, port);
        cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channel);
        cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE,
                WMQConstants.WMQ_CM_CLIENT);

// cf.setIntProperty(WMQConstants.WMQ_CONNECT_OPTIONS,10);
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER,
queueManagerName);

Enumeration<?> enumer = cf.getPropertyNames();
while(enumer.hasMoreElements()){
System.out.println("enumer == " + enumer.nextElement().toString());
}

// Create JMS objects
begin = System.currentTimeMillis();

connection = cf.createConnection();
connection.start();
System.out.println("connected!");

如果工厂对象cf设置的属性值有问题,比如说主机名字不对,会抛出异常,可是,等待抛出异常的时间比较久,30秒,所以我想问的是,怎么设置创建连接的超时时间。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!