• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resource allocation in ejbCreate/ejbRemove

 
Wora Supha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spec. page 82
---------------
...

If the session bean instance allocates resources in the ejbCreate<METHOD>(...) method and/or in the business methods, and normally releases the resources in the ejbRemove() method, these resources will not be automatically released in the above scenarios. The application using the session bean should provide some clean up mechanism to periodically clean up the unreleased resources.
---------------


If I open database connection in the ejbCreate and close in the ejbRemove, how can I maintain the opened connection which are never been closed?
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wora,

I'd suggest that one should always clean up resources (db connections, file streams, etc) before exiting the bean's method.

 
Wora Supha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's mean we have to do

try{
..
}catch(RuntimeException e){
..
con.close();
}

in every business methods?
 
Arun Krishnamoorthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are concerned only about pooled connections (database,resource manager etc), closing the pooled connection in each business method is a very good idea. Since these are pooled, the overhead for returning a connection back to the pool is minimal (just a local invocation on a method in the call stack).

If you are maintaining connectivity to some external legacy systems and it is imperative for you to hold on to your socket connections over multiple business method calls due to a huge overhead in reacquiring socket connections, you could set the socket connection timeouts while acquiring your socket connection. This would ascertain these resources being released even if the ejbRemove() method does not get called.
 
Wora Supha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic