I don't really understand how changing the HashSet -> ArrayList really helps distribution of load. It might change the iteration order, but the order then wouldn't change.
Here's what I think is the problem.
1. No receivers
2. Queue receives, say 100 messages
3. A receiver is added
When the receiver is added, it gets blasted all 100 messages
4. Another receiver is added
5. A message comes in, it goes to the first receiver, the second is ignored. Etc.
(3) is a hard to solve problem, but at least (5) would be easy enough to fix. It would be a matter of looping the iteration per message. Numbers-wise the load then would be distributed evenly, but not necessarily fairly.
Why don't we see this with MDB? Because there's one connection with multiple sessions. Multiple connections is probably the cause of this.
Ignore what I wrote above. I should just shut up and drink my tea when I haven't taken a good look at the code....
Every time a message is added, the receiver is removed, and when the receiver is done processing it's added back. For hashtables, objects are returned by an iterator in the order of (Object.hashcode % bucket).
As it doesn't seem like constant-time access is very much needed, I would recommend changing to a List. However, I would probably use a LinkedList over an ArrayList, because items are removed from the head and added to the tail.
Thanks for the replies.
By what method can I suggest this as a change to JBossMQ? I didn't want to enter it as a bug since it's not really a bug. I think it makes the most since to make this configurable somehow since for some apps the current message distribution may make sense and for others, round-robin makes sense.