java - 为 MessageListener 调用 stop() 并暂时暂停连接传入消息的传递的正确位置。(JMSCC0012..)?

标签 java asynchronous jms ibm-mq mq

正如我在 JMS 规范中看到的,对于异步 MessageListener,无法从 onMessage() 调用 connection.stop() 。 能否请您告知调用connection.stop()以暂停传入消息的传递的正确位置并且不会出现异常:“JMSCC0012:方法“stop()”可能不从消息监听器调用。” 并在发生某个事件后自动恢复连接?使用 connection.stop() 的最佳实践是什么?

From JMS 2.0 spec:

6.1.5. Pausing delivery of incoming messages If any message listeners are running when stop is invoked, stop must wait until all of them have returned before it may return. While these message listeners are completing, they must have the full services of the connection available to them. A message listener must not attempt to stop its own connection as this would lead to deadlock. The JMS provider must detect this and throw a javax.jms.IllegalStateException.

From jms 1.1:

4.3.4 Pausing Delivery of Incoming Messages If MessageListeners are running when stop is invoked, stop must wait until all of them have returned before it may return. While these MessageListeners are completing, they must have the full services of the connection available to them.

最佳答案

我的解决方案是从 onMessage() 设置 volatile boolean 变量 suspendConnection。并从解析消息的其他线程检查此变量。当变量 suspendConnectiononMessage() 内设置时,我从解析器线程调用 connection.stop()

关于java - 为 MessageListener 调用 stop() 并暂时暂停连接传入消息的传递的正确位置。(JMSCC0012..)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48525941/

相关文章:

java - 两个不同的 Activity 中有两个不同的 SwitchCompat

java - 用于生成邻接矩阵的 k 数组树

javascript - 如何正确使用Promise.all?

c# - 使用 AJAX 或 ASP.NET 进行异步调用?

java - 使用 jms spring 和 activemq 队列的聊天应用程序

java - com.solacesystems.jms.ConfigurationException : Invalid scheme "null" in host "null://x.x.x.x:x"

jms - ActiveMQ "Classic"- 检测消息重复

java - 我能否在 Mac OS X 上为 Swing 获得原生外观的 JPopupMenu 外观?

c# - 在面向服务的架构 (SOA) 中,每个服务都应该拥有自己的数据吗?

c# - 将循环计数器传递给下面基于任务的方法时出现故障的原因是什么?