On 01/22/2014 10:52 PM, Li Li wrote:
I found the problem. I have only 160 messages and all are dispatched
to a single worker.
how to avoid this?

You need to set the consumer prefetch.
http://activemq.apache.org/what-is-the-prefetch-limit-for.html


On Thu, Jan 23, 2014 at 11:27 AM, Li Li <fancye...@gmail.com> wrote:
I modified it to use multithreads, but still only one work.
I use jstack and find other threads are blocked by Message msg =
receiver.receive();

public class Worker extends Thread{
     public Worker() throws Exception{
         recvConnFactory = new ActiveMQConnectionFactory(
                 queueConnString);
         recvQConn = recvConnFactory.
createQueueConnection();
         recvQConn.start();
         recvSession = recvQConn.createQueueSession(false,
Session.CLIENT_ACKNOWLEDGE);
         Queue queue = recvSession.createQueue("queue");
         receiver = recvSession.createReceiver(queue);

     }
     @Override
     public void run() {
         while (true) {
             try {
                 Message msg = receiver.receive();
                 if(!this.doWork(msg)){
                     break;
                 }
             } catch (JMSException e) {
                 logger.error(e.getMessage(), e);
             }
         }
     }
}

public class Main{
      public static void main(String[] args){
      Thread[] workers=new Worker[10];
      for(int i=0;i<workers.length;i++){
          workers[i]=new Worker();
          workers[i].start();
      }
      //sleep and wait
     for(int i=0;i<workers.length;i++){
        workers[i].join();
     }
}

On Thu, Jan 23, 2014 at 11:12 AM, kimmking <kimmking...@gmail.com> wrote:
Because you have only one thread -- main thread, no more threads created.




Beijing,China
Kimm King
skype: kimmking
github.com/kimmking



--
View this message in context: 
http://activemq.2283324.n4.nabble.com/why-only-one-thread-working-tp4676688p4676689.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


--
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.b...@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/

Reply via email to