2
votes

As I can see in JMS specification connection.stop() can't be called from onMessage() for asynchronous MessageListener. Could you please advise the right place to call connection.stop() to suspend delivery of incoming messages and don't get exception: "JMSCC0012: The method 'stop()' may not be called from a message Listener." and automatically resume the connection after some event? What the best practices of using 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.

1

1 Answers

2
votes

The solution in my case was to setup volatile boolean variable suspendConnection from onMessage(). And check this variable from other thread which parsing messages. When variable suspendConnection was setup inside onMessage() I call connection.stop() from parser thread.