• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about MDB

 
Li Xin
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a BMT MDB, what will happen if the onMessage() method just returns before the transaction is committed? Like this:
void onMessage() {
UserTransaction ut = ctx.getUsertransaction();
ut.begin();
.
.
return;
ut.commit();
}
Will an exception be thrown?
 
Jack Zhou
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

For a BMT MDB, what will happen if the onMessage() method just returns before the transaction is committed? Like this:
void onMessage() {
UserTransaction ut = ctx.getUsertransaction();
ut.begin();
.
.
return;
ut.commit();
}
Will an exception be thrown?

First all I belive the code should not compile. Something like "unreachable code error" will be ouput by compiler. If it compiles and run, then the transaction will not commit and finally there could be transaction time out exceptions originated from whatever the transaction manager is being used by the EJB server.
 
salmaan ahsan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly feel that the code should not compile, it should give compilation error of Unreachable code
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe there are 2 separate issues:
1. Message acknowledgement
2. Transaction management
For issue 1, if I understand the spec correctly [pg 316-317], for BMT beans the message acknowledgement is not part of the transaction. The EJB spec doesn't say when the ACK happens, but from the JMS spec I'd suspect it happens as soon as you return from onMessage. How or when you commit isn't relevant.
As for the second part, if you return from a method without committing the transaction, then your BMT MDB code is just plain broken. The spec doesn't say you can't write broken code, but obviously you can't expect good things to happen. There is no association between client and MDB onMessage transactions, so nobody else will have an opportunity to commit the transaction. Effectively you'll have a resource leak and eventually the server might crash.
 
Todor Mollov
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For sure some kind of Exception will be thrown , but I don't know what kind. EJB spec p.341 17.3.3
A stateless session bean instance must commit a transaction before a business method returns.
A message-driven bean instance must commit a transaction before the onMessage method returns.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic