On January 27th, this site will be read-only as we migrate to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,629 Users
  • 2,269,769 Discussions


Strange behavior with QueueBrowser

922859 Member Posts: 2
edited Mar 9, 2012 1:52PM in Java Message Service (JMS)

I am using a QueueBrowser along with a QueueReceiver for my application and notice behavior that is strange. Here is the logic :

a) I create a QueueBrowser against a queue and take a snapshot of whats on the queue.
b) I loop through the enumeration of messages on the queue and determine for each message , if the message is ready to be processed now(based on some logic).
c) If in step (b), i determine that the message is ready to be processed, i create a runnable and submit the runnable to a thread pool for processing.
d) The runnable uses a queue receiver to receive a specific message off the queue using a message selector and processes the message.

What i notice is if the receiver tries to receive a message that the browser has already seen, at times the receive method returns null. But eventually after many failed attempts, the receiver can pull the message off the queue using the message selector. Also, i notice that when the receive timeout is set to NO_WAIT,
the receive call fails before succeeding eventually. But if i use the receive method with a couple of seconds timeout, it does seem to receive successfully every time.

Any thoughts on why this behavior would happen?



  • 919856 wrote:

    Any thoughts on why this behavior would happen?
    Just to check: So if you use receive(2000) your test works every time, but if you use receiveNoWait() it sometimes fails to receive the message

    If so this is because of the way your JMS provider has implemented receiveNoWait(); This method is required to return immediately, which isn't enough time for the message to arrive from the server.

    Nigel Deakin-Oracle
  • 922859
    922859 Member Posts: 2

    Thanks for your quick response. That is exactly the behavior i see. Receive with no wait fails at times but receive with a wait of even 1 second seems to work.

    I saw this with ActiveMQ using both the embedded broker and an external broker.

  • It's best to avoid receiveNoWait() for the reason you've discovered.

    I'll try to clarify this in JMS 2.0. I've just logged this as

This discussion has been closed.