This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Releasing resources in a stateful session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Releasing resources in a stateful session bean" Watch "Releasing resources in a stateful session bean" New topic
Author

Releasing resources in a stateful session bean

Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
Hello,I'm developing an EJB2 Session bean that keeps a JMSConnection open while it's active. I'm closing the connection in ejbRemove() and ejbPassivate(), but is that enough? As I understand it, neither of these callbacks are called if a system exception is thrown, so will the Resource Manager know to release the connection if the bean is destroyed that way? Or should all my methods have a try-catch for RuntimeExceptions and close the connection in the catch block before rethrowing the exception?

Thank you,
Yuriy
Rikard Qvarforth
Ranch Hand

Joined: Jul 10, 2001
Posts: 107
well in session bean the ejbActivate and ejbPassivate methods is where you should aqureire and relese resources before the bean is passivated or activated by the container. For runtime exception you cant be sure of so make your implemention code in theese callbacks(hookmethods) and you should be safe

Regards Rikard
 
 
subject: Releasing resources in a stateful session bean