title: Browse Jms Queue in a multiThreading way
body: <p>I have a spring-batch which browses Queue messages, this queue supposed to contain a huge number of messages. then it takes a lot of time to treat all of them. therefore i thought about multi-Threading to deal with the issue, but it's not clear for me yet.</p>
  
  <p>Here is an example of browsing a Queue without multithreading:</p>
  
  <pre><code>
  import java.net.URISyntaxException;
  import java.util.Enumeration;
  
  import javax.jms.Connection;
  import javax.jms.ConnectionFactory;
  import javax.jms.Message;
  import javax.jms.MessageConsumer;
  import javax.jms.MessageProducer;
  import javax.jms.Queue;
  import javax.jms.QueueBrowser;
  import javax.jms.Session;
  import javax.jms.TextMessage;
  
  import org.apache.activemq.ActiveMQConnectionFactory;
  
  public class JmsQueueBrowseExample {
      public static void main(String[] args) throws URISyntaxException, Exception {
          Connection connection = null;
          try {
              // Producer
              ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                      "tcp://localhost:61616");
              connection = connectionFactory.createConnection();
              Session session = connection.createSession(false,
                      Session.AUTO_ACKNOWLEDGE);
              Queue queue = session.createQueue("browseQueue");
              MessageConsumer consumer = session.createConsumer(queue);
              connection.start();
  
              System.out.println("Browse through the elements in queue");
              QueueBrowser browser = session.createBrowser(queue);
              Enumeration e = browser.getEnumeration();
              //Multithreading here
              while (e.hasMoreElements()) {
                  TextMessage message = (TextMessage) e.nextElement();
                  System.out.println("Browse [" + message.getText() + "]");
              }
              System.out.println("Done");
              browser.close();
  
              session.close();
          } finally {
              if (connection != null) {
                  connection.close();
              }
          }
      }
  
  }
  </code></pre>
  
  <p>Thank you</p>