• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transactions in MDB's

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

What happens when a RunTimeException occurs in an MDB that was processing some message? What happens to the original message? Will it be put back to the Queue and if so how ? Help!
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi,

I think your question is incomplete, BUT IM NOT 100 % SURE. you should specify Runtime Ex is a App Ex or Sys Ex, and Tr argument of MDB


Thanks,
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What happens to the original message? Will it be put back to the Queue and if so how ?
Usually the runtime exception will lead to a rollback. What then happens to your message depends on the transaction type: In CMT the message will be put back into the queue and will be processed again (probably throwing the same runtime exception again, and so on); in BMT your message is deleted from the queue and can't be recovered.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ralph Jaus:
[QB]Hi,
Usually the runtime exception will lead to a rollback.


I can't agree on that.. All Runtime Exceptions are not System Exceptions,

Only System Exceptions lead to rollback
 
Tomaszz Lewandowski
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also disagree with the statement:

... in BMT your message is deleted from the queue and can't be recovered. ...

Core spec, section 5.4.17 says:

If a message-driven bean uses bean-managed transaction demarcation and throws a RuntimeException, the container should not acknowledge the message

so I think that in this case the message will not be deleted from queue.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't agree on that.. All Runtime Exceptions are not System Exceptions,
By "usually" I meant those runtime exceptions that are not application exceptions. But of course you're right: It's always better to use the terms "application exception" and "system exception".
so I think that in this case the message will not be deleted from queue
The core spec, 5.4.12 says:
When a message-driven bean using bean-managed transaction demarcation uses the javax.transaction.UserTransaction interface to demarcate transactions, the message receipt that causes the bean to be invoked is not part of the transaction. If the message receipt is to be part of the transaction, container-managed demarcation with the REQUIRED transaction attribute must be used.
Note: Queuing systems work in a transactional way. So if in BMT the physical removal of the message from the queue would depend on the result of the user transaction you would need an outer transaction handling the queue and spanning the inner user transaction. But there is no requirement for nested transactions in ejb.

By the way, using a simple message consumer you can easily check that in the questionable BMT scenario there is no message in the queue after a system exception occured in the MDB.

Regards
Ralph
---------------------------------
SCJP 5.0 (98%)
[ November 02, 2008: Message edited by: Ralph Jaus ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic