Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

A question about MDB

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic