Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt - MDB

 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers

I have a doubt on MDBs...If an application exception is caught on the onMessage method of a MDB and I found that it is not possible to continue there after....So in the catch block I call ctx.setRollbackOnly() and re-throw the exception. Now what will happen?...Will the container try to deliver the message again to some other instance from the same pool or will the container simply discard the instance and discard the message?.
 
pramoth suwanpech
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You make call ctx.setRollbackOnly() ,I assume that you use CMT MDB.

You can throws only System Exception ,in spec system exception will discard bean instance.
Then the container try to deliver msg other instance from the same pool(beacuase of method not complete).
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not asking about system exceptions...If I call ctx.setRollbackOnly() in the onMessage() method of a MDB then what will happen?.
 
Frank Ertl
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you use ctx.setRollbackOnly() I guess you are using CMT. With CMT the Message will be redelievered again and again and again...
That happens because the whole transaction (including the receipt of the message from the Queue) ist rolled back what means that the message is put back on the Queue.

Frank

[ October 10, 2005: Message edited by: Frank Ertl ]
[ October 10, 2005: Message edited by: Frank Ertl ]
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. Thanks. But what will happen if my bean throws a system exception in both the cases, BMT and CMT.
 
Frank Ertl
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use CMT the bean instance will be discarded and the transaction will be rolled back unless you specify the transaction attribute to "NotSupported".
With bean managed persistence the bean instance will be discarded, too, but what happens to the message depends on your acknowlegement policy ("auto-acknowledge" vs. "dups-ok-acknowledge").
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic