You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Li Li <fa...@gmail.com> on 2014/03/05 12:10:03 UTC

is msg.acknowledge thread safe in INDIVIDUAL_ACKNOWLEDGE mode?

hi all,
    I want to use INDIVIDUAL_ACKNOWLEDGE like this:
I have one session and a receiver thread. this thread receive messages
to ten worker thread.
each worker thread acknowledge it's message

receiver thread:
while(true){
      Message msg=receiver.receive();
      put msg to a ConcurrentLinkedList;
}

Worker thread:
while(true){
     Message msg=getMessgeFromLinkedList();
     process msg;
     msg.acknowledge();
}

is it thread safe?

I have debugged into ActiveMQMessageConsumer.acknowledge in 5.9.0

    void acknowledge(MessageDispatch md, byte ackType) throws JMSException {
        MessageAck ack = new MessageAck(md, ackType, 1);
        session.sendAck(ack);
        synchronized(deliveredMessages){
            deliveredMessages.remove(md);
        }
    }

1. it seems remove message from deliveredMessages is synchronized
2. session.sendAck(ack);
       sendAck(ack,false);
           asyncSendPacket(ack);
                connection.asyncSendPacket(command);
connection is thread safe, so message.acknowledge is thread-safe?

Re: is msg.acknowledge thread safe in INDIVIDUAL_ACKNOWLEDGE mode?

Posted by Timothy Bish <ta...@gmail.com>.
On 03/05/2014 08:33 PM, Li Li wrote:
> The message will be used by only one thread.
> what about CMS implementation? our team has many c++ users. is c++
> client the exactly the same logic as java?
yes

> On Thu, Mar 6, 2014 at 12:24 AM, artnaseef <ar...@artnaseef.com> wrote:
>> That sounds right to me. As long as each message object is not simultaneously used in more than one thread, you should be safe.
>>
>> Sent from my iPhone
>>
>>> On Mar 5, 2014, at 3:10 AM, "Li Li [via ActiveMQ]" <ml...@n4.nabble.com> wrote:
>>>
>>> hi all,
>>>      I want to use INDIVIDUAL_ACKNOWLEDGE like this:
>>> I have one session and a receiver thread. this thread receive messages
>>> to ten worker thread.
>>> each worker thread acknowledge it's message
>>>
>>> receiver thread:
>>> while(true){
>>>        Message msg=receiver.receive();
>>>        put msg to a ConcurrentLinkedList;
>>> }
>>>
>>> Worker thread:
>>> while(true){
>>>       Message msg=getMessgeFromLinkedList();
>>>       process msg;
>>>       msg.acknowledge();
>>> }
>>>
>>> is it thread safe?
>>>
>>> I have debugged into ActiveMQMessageConsumer.acknowledge in 5.9.0
>>>
>>>      void acknowledge(MessageDispatch md, byte ackType) throws JMSException {
>>>          MessageAck ack = new MessageAck(md, ackType, 1);
>>>          session.sendAck(ack);
>>>          synchronized(deliveredMessages){
>>>              deliveredMessages.remove(md);
>>>          }
>>>      }
>>>
>>> 1. it seems remove message from deliveredMessages is synchronized
>>> 2. session.sendAck(ack);
>>>         sendAck(ack,false);
>>>             asyncSendPacket(ack);
>>>                  connection.asyncSendPacket(command);
>>> connection is thread safe, so message.acknowledge is thread-safe?
>>>
>>>
>>> If you reply to this email, your message will be added to the discussion below:
>>> http://activemq.2283324.n4.nabble.com/is-msg-acknowledge-thread-safe-in-INDIVIDUAL-ACKNOWLEDGE-mode-tp4678545.html
>>> To start a new topic under ActiveMQ - Dev, email ml-node+s2283324n2368404h72@n4.nabble.com
>>> To unsubscribe from ActiveMQ - Dev, click here.
>>> NAML
>>
>>
>>
>> --
>> View this message in context: http://activemq.2283324.n4.nabble.com/is-msg-acknowledge-thread-safe-in-INDIVIDUAL-ACKNOWLEDGE-mode-tp4678545p4678553.html
>> Sent from the ActiveMQ - Dev 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/


Re: is msg.acknowledge thread safe in INDIVIDUAL_ACKNOWLEDGE mode?

Posted by Li Li <fa...@gmail.com>.
The message will be used by only one thread.
what about CMS implementation? our team has many c++ users. is c++
client the exactly the same logic as java?

On Thu, Mar 6, 2014 at 12:24 AM, artnaseef <ar...@artnaseef.com> wrote:
> That sounds right to me. As long as each message object is not simultaneously used in more than one thread, you should be safe.
>
> Sent from my iPhone
>
>> On Mar 5, 2014, at 3:10 AM, "Li Li [via ActiveMQ]" <ml...@n4.nabble.com> wrote:
>>
>> hi all,
>>     I want to use INDIVIDUAL_ACKNOWLEDGE like this:
>> I have one session and a receiver thread. this thread receive messages
>> to ten worker thread.
>> each worker thread acknowledge it's message
>>
>> receiver thread:
>> while(true){
>>       Message msg=receiver.receive();
>>       put msg to a ConcurrentLinkedList;
>> }
>>
>> Worker thread:
>> while(true){
>>      Message msg=getMessgeFromLinkedList();
>>      process msg;
>>      msg.acknowledge();
>> }
>>
>> is it thread safe?
>>
>> I have debugged into ActiveMQMessageConsumer.acknowledge in 5.9.0
>>
>>     void acknowledge(MessageDispatch md, byte ackType) throws JMSException {
>>         MessageAck ack = new MessageAck(md, ackType, 1);
>>         session.sendAck(ack);
>>         synchronized(deliveredMessages){
>>             deliveredMessages.remove(md);
>>         }
>>     }
>>
>> 1. it seems remove message from deliveredMessages is synchronized
>> 2. session.sendAck(ack);
>>        sendAck(ack,false);
>>            asyncSendPacket(ack);
>>                 connection.asyncSendPacket(command);
>> connection is thread safe, so message.acknowledge is thread-safe?
>>
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://activemq.2283324.n4.nabble.com/is-msg-acknowledge-thread-safe-in-INDIVIDUAL-ACKNOWLEDGE-mode-tp4678545.html
>> To start a new topic under ActiveMQ - Dev, email ml-node+s2283324n2368404h72@n4.nabble.com
>> To unsubscribe from ActiveMQ - Dev, click here.
>> NAML
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/is-msg-acknowledge-thread-safe-in-INDIVIDUAL-ACKNOWLEDGE-mode-tp4678545p4678553.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: is msg.acknowledge thread safe in INDIVIDUAL_ACKNOWLEDGE mode?

Posted by artnaseef <ar...@artnaseef.com>.
That sounds right to me. As long as each message object is not simultaneously used in more than one thread, you should be safe. 

Sent from my iPhone

> On Mar 5, 2014, at 3:10 AM, "Li Li [via ActiveMQ]" <ml...@n4.nabble.com> wrote:
> 
> hi all, 
>     I want to use INDIVIDUAL_ACKNOWLEDGE like this: 
> I have one session and a receiver thread. this thread receive messages 
> to ten worker thread. 
> each worker thread acknowledge it's message 
> 
> receiver thread: 
> while(true){ 
>       Message msg=receiver.receive(); 
>       put msg to a ConcurrentLinkedList; 
> } 
> 
> Worker thread: 
> while(true){ 
>      Message msg=getMessgeFromLinkedList(); 
>      process msg; 
>      msg.acknowledge(); 
> } 
> 
> is it thread safe? 
> 
> I have debugged into ActiveMQMessageConsumer.acknowledge in 5.9.0 
> 
>     void acknowledge(MessageDispatch md, byte ackType) throws JMSException { 
>         MessageAck ack = new MessageAck(md, ackType, 1); 
>         session.sendAck(ack); 
>         synchronized(deliveredMessages){ 
>             deliveredMessages.remove(md); 
>         } 
>     } 
> 
> 1. it seems remove message from deliveredMessages is synchronized 
> 2. session.sendAck(ack); 
>        sendAck(ack,false); 
>            asyncSendPacket(ack); 
>                 connection.asyncSendPacket(command); 
> connection is thread safe, so message.acknowledge is thread-safe? 
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://activemq.2283324.n4.nabble.com/is-msg-acknowledge-thread-safe-in-INDIVIDUAL-ACKNOWLEDGE-mode-tp4678545.html
> To start a new topic under ActiveMQ - Dev, email ml-node+s2283324n2368404h72@n4.nabble.com 
> To unsubscribe from ActiveMQ - Dev, click here.
> NAML




--
View this message in context: http://activemq.2283324.n4.nabble.com/is-msg-acknowledge-thread-safe-in-INDIVIDUAL-ACKNOWLEDGE-mode-tp4678545p4678553.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.