Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

explicit releaseSession after getSession

 
John Aiken
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was under the impression that one has to explicitly call releaseSession() after a getSession() or am I mistaken?

I am trying to diagnose a possible connection leak in our application. We have a DAO that extends HibernateDaoSupport. Some methods use the HibernateTemplate which I know handles everything automatically, other methods have calls to getSession() but in the method there is no corresponding call to releaseSession().

The Hibernate SessionFactory is injected to the DAO through Spring, a pretty standardized configuration. There is advice that is applied to this method as well which just has a propagation="REQUIRED" and nothing else.

The Hibernate session for the application UI is established via the OpenSessionInView pattern.

The strange thing is that our connection pool gets exhausted only under some scenarios i.e. when we are running some concurrent tasks performed by non-UI worker threads, just using the UI for any amount of time does not result in an increase in # of active pool connections. We have our connection pool set to max 30 connections, the app spawns a batch of 16 worker threads, after these are done the connections are not released, the next batch of 16 worker threads exhausts the pool as only 30-16=14 connections are available...so there is a leak somewhere and I think perhaps what I found above?
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever the HibernateTemplate calls "getSession()" it eventually calls "releaseSession()". I'm pretty sure you have to follow the same pattern or you will see the kind of behavior you are seeing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic