activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Li <>
Subject multithreads share a session problem
Date Wed, 22 Jan 2014 10:50:17 GMT
hi all
   I want to share a session among many threads and after do real work
the message is acknowledged:

   class Dispatcher  implements MessageListener{
        Thread[] workers;
        public void init(){
            session = connection.createQueueSession(false,
            Queue queue = session.createQueue("workingqueue");
            QueueReceiver receiver = session.createReceiver(queue);

        public void onMessage(Message message) {
             send this message to a worker thread


    class Worker extends Thread{

          public void run(){
                    //get a message from dispatcher
                    Message message=....

    After reading and
    I know it's wrong because Worker1 call message.acknowledge() will
also acknowledge Worker2's message--even it's not acknowledged by

    So I have to let each Worker has its own session. But it seems not
very efficient.
    Any better solutions? Thank you.

View raw message