【发布时间】:2014-01-27 14:36:56
【问题描述】:
我有一个从 MQ 读取的 java 方法,如下所示:
public String getMessage() throws SecurityException, IOException {
MQMessage rcvMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
gmo.options = MQC.MQGMO_WAIT;
int openOptions_1 = MQC.MQOO_INPUT_AS_Q_DEF;
if (log.isInfoEnabled()) {
log.info("Accessing queue: " + qName_out_get);
}
MQQueue queue1;
String msgText = null;
try {
MQQueueManager qMgr = new MQQueueManager(qManager);
queue1 = qMgr.accessQueue(qName_out_get, openOptions_1);
queue1.get(rcvMessage, gmo);
byte[] buffer = new byte[rcvMessage.getMessageLength()];
rcvMessage.readFully(buffer);
msgText = new String(buffer);
log.info("Final message is : " + msgText);
} catch (MQException ex) {
log.error("A WebSphere MQ Error occured : Completion Code "
+ ex.completionCode
+ " Reason Code "
+ ex.reasonCode);
for (Throwable t = ex.getCause(); t != null; t = t.getCause()) {
log.error("... Caused by ");
}
} catch (IOException e) {
log.error("An IOException occured whilst writing to the message buffer: "
+ e);
}
finally {
queue1.close();
qMgr.disconnect();
}
return msgText;
}
我有代码在 finally 块中关闭队列并断开与队列管理器的连接 但是,与队列管理器的连接并没有关闭。 有人能帮我一下吗? 提前致谢
【问题讨论】:
-
你怎么说与队列管理器的连接没有关闭?可以提供线程转储吗?
-
队列管理器由其他组织维护。他们最后使用
dis chstatus命令进行了检查 -
MQException 类的 disconnect() 函数抛出缓存的异常,您没有在 finally 块中处理。甚至不确定您的代码是如何编译的。我猜你的 disconnect() 调用失败了。
-
我正在处理 MQ 异常,断开队列管理器和关闭队列的代码位于 try catch 块中,其中处理 MQException...这还不够,还是我必须显式处理 cachedException?
-
disconnect() 在你的 finally 语句中,它在 catch 语句之外。所以需要处理 disconnect() 抛出的 MQException,因为它是一个缓存的异常。方法的签名是
public void disconnect() throws MQException。
标签: java queue message-queue ibm-mq