activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Li <fancye...@gmail.com>
Subject Re: why only one thread working?
Date Thu, 23 Jan 2014 03:52:25 GMT
I found the problem. I have only 160 messages and all are dispatched
to a single worker.
how to avoid this?

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.

Mime
View raw message