Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reason for cleanup in ejbRemove  RSS feed

 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My query is what happens when i donot release resources such as data base connection acquired during the bean creation, in ejbRemove?
That is, What is the problem if i have a data base connection open when the bean is set to be removed by the container(may be due to a runtime exception)?
Thanks in advance
William Kane
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is -- it depends on the container. In most cases, EJB containers have a "reaping" thread in their database connection code that will eventually recover lost connections that are not released.

However, it's generally a BAD idea to hold onto a database connection in an EJB creation anyway -- in most cases the length you own a database connection should be no longer than the execution length of a single method.

Kyle
 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
The answer is -- it depends on the container. In most cases, EJB containers have a "reaping" thread in their database connection code that will eventually recover lost connections that are not released.

However, it's generally a BAD idea to hold onto a database connection in an EJB creation anyway -- in most cases the length you own a database connection should be no longer than the execution length of a single method.

Kyle


Thanks Kyle,
Can you be a little more specific about what 'recovering' of connections means.Is it that these connections are 'closed' by the thread and returned back to the connection pool?
In the face of an event when the thread is not implemented by the server what happens to the connections that are not closed during the ejbRemove methods.Will these connections remain open even after the bean instance is garbage collected?If yes, what is consequence of many such connections remaaining open?
Thanks again,
Willian Kane
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it means that if a connection is not returned to the pool that the reaper thread will close it and return it to the pool.

Kyle
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!