title: How to run DefaultMessageListenerContainer on the 'main' thread
body: <p>I have a case where i want to run DefaultMessageListenerContainer in the same 'main' thread. Right now it uses SimpleAsyncTaskExecutor which spawns new thread every time it receives a message. </p>
  
  <p>We have a test case which connects to different distributed system and do the processing and in the end it asserts few things. As DefaultMessageListenerContainer runs in seperate thread, main thread returns and start executing assertions before DefaultMessageListenerContainer can complete. This leads to failure of the test case. As work around we have made the main thread to sleep for few seconds.</p>
  
  <p>Sample config</p>
  
  <pre><code>  &lt;int-jms:message-driven-channel-adapter
          id="mq.txbus.publisher.channel.adapter"
          container="defaultMessageListenerContainer"
          channel="inbound.endpoint.publisher"
          acknowledge="transacted"
          extract-payload="true" /&gt;
  
    &lt;beans:bean id="defaultMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;
      &lt;beans:property name="connectionFactory" ref="mockConnectionFactory"/&gt;
      &lt;beans:property name="destination" ref="publisherToTxmQueue"/&gt;
      &lt;beans:property name="taskExecutor" ref="taskExecutor"/&gt;
      &lt;beans:property name="maxMessagesPerTask" value="10"/&gt;
      &lt;beans:property name="sessionTransacted" value="true"/&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="taskExecutor" class="org.springframework.scheduling.timer.TimerTaskExecutor" /&gt;
  </code></pre>
  
  <p>I am trying to use TimerTaskExecutor here because it creates single thread but that thread is seperate than main thread so problem is unresolved. I tried using SyncTaskExecutor but that does not work either (or may be i dint provide the correct property value?).</p>
  
  <p><strong>Answer:</strong><br>
  We solved this problem by using SimpleMessageListenerContainer.
  This is the new config</p>
  
  <pre><code>     &lt;int-jms:message-driven-channel-adapter
          id="mq.txbus.publisher.channel.adapter"
          container="messageListenerContainer"
          channel="inbound.endpoint.publisher"
          acknowledge="transacted"
          extract-payload="true" /&gt;
  
  &lt;beans:bean id="messageListenerContainer" class="org.springframework.jms.listener.SimpleMessageListenerContainer"&gt;     
      &lt;beans:property name="connectionFactory" ref="mockConnectionFactory"/&gt;     
      &lt;beans:property name="destination" ref="publisherToTxmQueue"/&gt;
      &lt;beans:property name="sessionTransacted" value="true"/&gt;
      &lt;beans:property name="exposeListenerSession" value="false"/&gt;
  &lt;/beans:bean&gt; 
  </code></pre>