title: activemq - wait for all messages to be consumed
body: <p>I have a case where there's a bulk action that is processing multiple items. After all items are processed I have to update the action status to completed. Items are processed in parallel by multiple consumers.</p>
  
  <p>In theory a consumer after processing an item could check if there are no items left (or no messages in the queue for this action), but it's possible, that two consumers (A and B) finish at the same time, they both check at the same time and they both see that the other one is still not ready (because the transaction is not yet committed) - consumer A will not see changes done by consumer B and consumer B will not see changes done by consumer A, so none of them would update action status. Am I right?</p>
  
  <p>How to implement such condition without some kind of additional periodic check of the status and without its overhead? Periodic check might be good if there are thousands of items per action, but if there are usually 1-2 long-running ones it's very inefficient.</p>
  
  <p>Thanks!</p>
  
  <p>edit: in short - what is the correct approach to trigger some action after processing a set of messages, but:</p>
  
  <ul>
  <li>messages must be processed in parallel</li>
  <li>periodic checking if all messages were processed is not the answer</li>
  </ul>