activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: why only one thread working?
Date Thu, 23 Jan 2014 11:15:43 GMT
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 <fancyerii@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.cn@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.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/


Mime
View raw message