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

Resource allocation in ejbCreate/ejbRemove

 
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?
 
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?
 
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,
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic