正如我在 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
。并从解析消息的其他线程检查此变量。当变量 suspendConnection
在 onMessage()
内设置时,我从解析器线程调用 connection.stop()
。
关于java - 为 MessageListener 调用 stop() 并暂时暂停连接传入消息的传递的正确位置。(JMSCC0012..)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48525941/