How to start/stop ActiveMQ listener programatically?

Hi Experts,
I have ActiveMQ 5.4 and Spring3.1. This MessageListener will be kicked off once there is a message dropped in the queue. Because this MessageListener will insert a large amount of data, I wonder if there is a way to stop this Listener, and restart it once the a large amount of data inserted into DB.
How to stop/restart the listener programatically? Thanks!

public class ExampleListener implements MessageListener {
      public void onMessage(Message message) {
                        insert a LARGE amount of data into DB table using Hibernate.
                        I       
      }
}



This is Spring ApplicationContext.xml

<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
      <constructor-arg>
      <value>HelloWorldQueue</value>
      </constructor-arg>
</bean>
 <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
 <property name="connectionFactory">
  <bean class="org.apache.activemq.ActiveMQConnectionFactory">
 <property name="brokerURL">
<value>tcp://localhost:61616</value>
 </property>
 </bean>
</property>
</bean>
      <bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
          <property name="connectionFactory" ref="jmsFactory"/>
      </bean>      
      <!-- this is the Message Driven POJO (MDP) -->
      <bean id="messageListener" class="com.sprint.cto.sp.helloworld.ExampleListener" />
      
      <!-- and this is the message listener container -->
      <bean id="jmsContainer"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="connectionFactory" ref="jmsFactory"/>
            <property name="destination" ref="destination"/>
            <property name="messageListener" ref="messageListener" />
      </bean>
      
SarahDengAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
thats not possible sorry
mccarlIT Business Systems Analyst / Software DeveloperCommented:
As it is, that message listener will be single threaded, so while that thread is busy inserting the large amount of data into the DB, it won't be consuming anymore messages. Therefore, there is nothing to stop anyway!
ajaycvCommented:
Have you tried using the start method and the stop method on the DefaultMessageListenerContainer?

The DefaultMessageListenerContainer (DMLC) is another wonderful convenience class that is part of the Spring Framework's JMS package. As you can see in the Javadoc, the DMLC is not a single class, but a well-abstracted hierarchy for the purpose of receiving messages. The reason for this is that the DMLC takes its inspiration from Message Driven Beans (MDB).

http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/jms/listener/DefaultMessageListenerContainer.html
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

SarahDengAuthor Commented:
Thanks! The question is well answered!
ajaycv,
 I want to learn more about how to stop/restart DMLC, do you have any example I can use? Thanks!
SarahDengAuthor Commented:
Do I need to configure "DefaultMessageListenerContainer " or other connectionFactory as such to work well in the use case (it would insert a large data into DB, it takes a longer time to finish)? There is Another message Listener listens to another queue will remove some records from this SAME table.
If I use the default configuration I may get timeout or exception in this case.
Please comment.
ajaycvCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SarahDengAuthor Commented:
Thanks!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.