title: Gracefully stop DefaultMessageListenerContainer having a receiveTimeout = -1
body: <p>Can somebody point me to a way to grecefully stop a DefaultMessageListenerContainer in Spring that is defined with a <code>receiveTimeout = -1</code> (i.e. it is using the blocking version of javax.jms.MessageConsumer#receive) ?</p>
  
  <p>Actually, I've tried both stop() and shutdown() methods of DMLC but consumer thread is stuck on the receive() call.</p>
  
  <pre><code>"heartBeatContainer-1" prio=6 tid=0x0304d800 nid=0x1d20 in Object.wait() [0x037ef000]
  java.lang.Thread.State: WAITING (on object monitor)
      at java.lang.Object.wait(Native Method)
      - waiting on &lt;0x22c48ab0&gt; (a java.lang.Object)
      at java.lang.Object.wait(Object.java:485)
      at org.apache.activemq.SimplePriorityMessageDispatchChannel.dequeue(SimplePriorityMessageDispatchChannel.java:87)
      - locked &lt;0x22c48ab0&gt; (a java.lang.Object)
      at org.apache.activemq.ActiveMQMessageConsumer.dequeue(ActiveMQMessageConsumer.java:452)
      at org.apache.activemq.ActiveMQMessageConsumer.receive(ActiveMQMessageConsumer.java:504)
      at org.springframework.jms.connection.CachedMessageConsumer.receive(CachedMessageConsumer.java:70)
      at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveMessage(AbstractPollingMessageListenerContainer.java:430)
      at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:310)
      at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
      at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1069)
      at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1061)
      at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:958)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>I cannot close the connection as there are other listeners that should continue to consume messages.</p>