I am new to jms. The goal is to process messages concurrently from a queue in an asynchronous listener\'s onMessage method by attaching a listener instance to multiple consume
I only took a brief look and I noticed that you pass the wrong consumer to your second thread:
Thread newThread2 = new Thread(consumer1); // has to pass consumer2
beside of this, some variables such as ConnectionFactory
are static and initialized multiple times/overriden. You only need one connection that could create multiple sessions and/or consumers.
Related to the code example you provided, It is not recommanded by Oracle to create low-level threads on a deployed application. Example for Weblogic : Using Threads in WebLogic Server
Instead in the applicationcontext.xml, where you have made the bean of mail container, you can add concurrent consumer property which would be a better approach.
<bean id="jmsMailContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers">
<value>100</value>
</property>
<property name="connectionFactory" ref="connectionFactory"/>
<property name="destination" ref="mailDestination"/>
<property name="messageListener" ref="jmsMailConsumer"/>