title: DefaultMessageListenerContainer threading issue
body: <p>I am using Spring JMS 4.1.</p>
  
  <p>Since a previous post ([Use of <code>CachingConnectionFactory</code> with <a href="https://stackoverflow.com/questions/27022181/prevent-use-of-cachingconnectionfactory-with-defaultjmslistenercontainerfactory"><code>DefaultJmsListenerContainerFactory</code></a>) I have been using a <code>CachingConnectionFactory</code> (setting <code>cacheConsumers</code> to <code>false</code>) with the <code>DefaultJmsListenerContainerFactory</code>:</p>
  
  <pre><code>&lt;bean id="cachedConnectionFactory" 
            class="org.springframework.jms.connection.CachingConnectionFactory"
          p:targetConnectionFactory-ref="jmsConnectionFactory"
          p:cacheConsumers="false"
          p:sessionCacheSize="3" /&gt;
  &lt;bean id="jmsListenerContainerFactory"
            class="org.springframework.jms.config.DefaultJmsListenerContainerFactory"
            p:connectionFactory-ref="cachedConnectionFactory"
            p:destinationResolver-ref="jndiDestinationResolver"
            p:concurrency="3-5"
            p:backOff-ref="exponentialBackOff"
            p:receiveTimeout="1000" /&gt;
  </code></pre>
  
  <p>I am now trying to use my listener class I did define programmatically:</p>
  
  <pre><code>public void configureJmsListeners(JmsListenerEndpointRegistrar registrar) {
      ...
      MyListener receiver = new MyListener();
      ...
      MessageListenerAdapter adapter = new MessageListenerAdapter(listener);
      adapter.setDefaultListenerMethod("onMessage");
      ...
      SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
      endpoint.setId(endpointId);
      endpoint.setDestination(...);
      endpoint.setMessageListener(adapter);
      registrar.registerEndpoint(endpoint);
  }
  </code></pre>
  
  <p>It is working since message are well received by my listener class but logs look weird. After the start, it looks like only one thread is processing messages even if there are several waiting for in the queue:</p>
  
  <pre><code>2014-12-29 15:10:53,978: INFO  [DefaultMessageListenerContainer-1] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:10:53,978: INFO  [DefaultMessageListenerContainer-3] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:10:53,978: INFO  [DefaultMessageListenerContainer-4] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:10:53,995: INFO  [DefaultMessageListenerContainer-2] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:11:05,318: INFO  [DefaultMessageListenerContainer-4] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:11:10,052: INFO  [DefaultMessageListenerContainer-4] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:11:14,506: INFO  [DefaultMessageListenerContainer-4] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:11:18,825: INFO  [DefaultMessageListenerContainer-4] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:11:21,715: INFO  [DefaultMessageListenerContainer-4] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:11:21,725: INFO  [DefaultMessageListenerContainer-5] [MyListener.instantiateProcess():164] - Processing message
  2014-12-29 15:11:25,152: INFO  [DefaultMessageListenerContainer-5] [MyListener.instantiateProcess():164] - Processing message
  ...
  DefaultMessageListenerContainer-5 only until all 60 remaining messages have been read...
  </code></pre>
  
  <p>As you can see eventually only the container #5 is used to process all remaining messages. Messages are not processed in parallel and the defined concurrency does not seem to be used.
  I don't know if it was the exact same issue but I had a look to this <a href="https://stackoverflow.com/questions/12583161/defaultmessagelistenercontainer-not-scaling">post</a> but I am not using ActiveMQ and I do not have this prefetch option.</p>
  
  <p>Could you please explain why I have this behavior. Is it a Spring misconfiguration or is the issue somewhere else?</p>
  
  <p>Thank you</p>
  
  <p><strong>EDIT</strong>:eventually I found an option on the messages broker to not keep messages order and things are getting better. There is a better threads use... 
  Nevertheless I can see that :</p>
  
  <ul>
  <li>first, the 5 <code>DefaultMessageListenerContainer</code> threads are used (max value in concurrency);</li>
  <li>when about 25 messages are remaining, only 3 (core value in concurrency) are processing messages;</li>
  <li>eventually only one is processing the 15 remaining messages...</li>
  </ul>
  
  <p>Why the maximum number of threads (5) or at least the core number (ie. 3) are not used almost until the queue has been completely emptied?</p>