Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

A question about MDB

 
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?
 
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.
 
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
 
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.
 
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.

 
I don't like that guy. The tiny ad agrees with me.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic