Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-3720

ActiveMqMessageConsumer should have a blocking message wait that does not require Session synchronization

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • None
    • 5.6.0
    • JMS client
    • None

    Description

      According to the documentation I've read and response to message posts, I've concluded that a call to consumer.receive(long) must guard against another thread using the session the consumer was created with.

      This makes it difficult to write performant code because a busy-wait idiom must be used in order to not hold a lock on session access while waiting for new messages. I've implemented a new method that will block until messages are available but does not require a session lock (it does not return any messages):

          /**
           * Waits until messages are available. Unless the caller is interrupted, there will be a message available when this
           * method returns.
           */
          public void waitUntilMessagesAvailable() {
            while (unconsumedMessages.isEmpty()) {
              synchronized (unconsumedMessages.getMutex()) {
                try {
                  unconsumedMessages.getMutex().wait(2000); // the dispatch channel notifies when a message arrives
                } catch (InterruptedException e) {
                  break;
                }
              }
            }
          }
      

      I'll be happy to submit as a patch with associated unit test if there is consensus that this is needed and useful.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mserrano Martin Serrano
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: