0

Could it be that MaxConcurrentListereners on a DistributedTxMessageListenerContainer isn't much of use? I have the impression that only one thread at a time can handle a message from the queue. Maybe it's logical since the message will only be removed from the queue once the transaction is successfull. Or am I wrong here?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244

1 Answers1

2

Yes, only one thread can receive a particular message from a queue.
Multiple threads can be receiving messages from a queue at any one time, though.
When a message is transactionally received from a queue, it becomes invisible to all other threads until the transaction aborts of commits.
If it aborts then the message reappears in the queue (made visible again); if it commits then the message is physically deleted from the queue.

Cheers
John Breakwell

John Breakwell
  • 4,667
  • 20
  • 25
  • Mmm, I'm afraid I'm still left with the same question. I have the impression that with transactional reads, only one thread at the time can handle a message. So, thread A would handle the top message. After being dealt with, either thread A or thread B handles next message. No concurrent processing is done. – Lieven Cardoen Jan 25 '11 at 18:28
  • Are you seeing a performance problem? What is giving you the impression of singlethreadedness? – John Breakwell Jan 28 '11 at 02:26
  • Because, when multiple messages are on the queue, I can see that they are not handled concurrent, but one after the other, even with two threads. – Lieven Cardoen Feb 01 '11 at 21:36
  • Maybe I'm seeing this wrong, but with a transaction to SqlServer for instance, the tables sometimes (depending on the kind of transaction) are locked so other threads won't be able to access them. I was thinking that the same thing happens with the queue. When on thread does a transactional read, unitl the transaction commits, another thread can't read the next message. Or am I wrong here? – Lieven Cardoen Feb 01 '11 at 21:37
  • @John Breakwell I can see in my Log4Net logs that, with two messages on the queue, the first thread does a transactional read, handles the message and commits the transaction. Then, and only then, the second thread reads the next message from the queue. I want the two threads to handle each a message at the same time, concurrent. – Lieven Cardoen Feb 01 '11 at 21:39
  • {{I wish I was a developer so I could just quickly put some code together to test this}} Let's say you have two apps - each has a start button which receives a transactional message within a transaction and a stop button which actually commits the transaction. And you press start on one and then the other. I'm not expecting the 2nd app to be blocked by the first app until the 1st app's stop button is pressed. I could be wrong, though. I'll try and find time to test the scenario you're descriving. – John Breakwell Feb 02 '11 at 16:38
  • That's exactly what I would want to do, Johh, but I have the impression that you'd be wrong. (but I could be wrong to). I have a system that uses your scenario and what I'm seeing is that the 2nd app is blocked. But maybe I'm still doing something wrong. Anyway, thx for you feedback and time! – Lieven Cardoen Feb 04 '11 at 10:17