title: How to understand the "synchronous" and "asynchronouns" messaging in JMS?
body: <p>After reading some document of JMS, I totally puzzled by the phrase <code>synchronous</code> and <code>asynchronouns</code>.</p>
  
  <p>See this page: <a href="http://docs.oracle.com/cd/E19798-01/821-1841/bncdq/index.html" rel="noreferrer">http://docs.oracle.com/cd/E19798-01/821-1841/bncdq/index.html</a></p>
  
  <p><strong>Synchronous</strong></p>
  
  <blockquote>
    <p>You use the receive method to consume a message synchronously. 
    You can use this method at any time after you call the start method:</p>
  
  <pre><code>connection.start();
  Message m = consumer.receive();
  connection.start();
  Message m = consumer.receive(1000); // time out after a second
  </code></pre>
    
    <p>To consume a message asynchronously, you use a message listener, described in the next section.</p>
  </blockquote>
  
  <p><strong>Asynchronous</strong></p>
  
  <blockquote>
    <p>JMS Message Listeners
    A message listener is an object that acts as an asynchronous event handler for messages.  This object implements the MessageListener interface, which contains one method, onMessage. In the onMessage method, you define the actions to be taken when a message arrives.</p>
    
    <p>You register the message listener with a specific MessageConsumer by using the setMessageListener method. For example, if you define a class named Listener that implements the MessageListener interface, you can register the message listener as follows:</p>
  
  <pre><code>Listener myListener = new Listener();
  consumer.setMessageListener(myListener);
  </code></pre>
  </blockquote>
  
  <p>I have two questions:</p>
  
  <ol>
  <li><p>As what I understood, the nature of JMS is asynchronous. Producer publishes messages to the queue/topic, it doesn't need to wait consumer. This is asynchronous behaviour. How can it be "synchronous"?</p></li>
  <li><p>If the "mesageListener" is asynchronous, but in my test with spring-jms, I found it always running in a thread. That means, if I write <code>Thread.sleep(2000)</code> in <code>onMessage</code>, it have to be wait 2 seconds before processing next message. Is it "asynchronous"?</p></li>
  </ol>