• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transactions in MDB's

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic