my dog learned polymorphism
The moose likes Object Relational Mapping and the fly likes Question on Java threads and Hibernate DAOs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Question on Java threads and Hibernate DAOs" Watch "Question on Java threads and Hibernate DAOs" New topic

Question on Java threads and Hibernate DAOs

Andres Delrotti
Ranch Hand

Joined: Aug 11, 2005
Posts: 163
Hi everyone,

I have a web application which has the back end code below....

In an action class method: something... domething....

MyCustomClass mcc = new MyCustomClass(); <--- in which this class implements runnable
mcc.setInputParameters(param1,param2, datasource) <----- datasource that was set in hibernate config file
new Thread(mcc).start();

*works fine**
** there are queries inside the class which gets connection from the same input datasource

I was suppose to do some code cleaning to enhance performance so I changed the implementation a bit....

In action class method: something.... something....

MyCustomClass mcc = new MyCustomClass();
mcc.setInputParameters(param1,param2) <----- datasource removed as input parameter
new Thread(mcc).start();

MyCustomClass was now set in the hibernate xml config file with dao classes defined as properties and those dao classes having the datasource as their property in the hibernate xml config file (the usual setup)

* in this type of setup, a connection leak happens. The number of connections in the pool increases rapidly when the class is run***
** the original queries in the class were transferred to the methods in the DAO classes**

Anyone has an idea why?

Thanks and I would appreciate any form of help
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 128

If you have some Connection Pool/instance management code inside your MyCustomClass, then it will happen. instead of having your code to manage connection instances/pool, you can use already built libraries for connection pool management.
I agree. Here's the link:
subject: Question on Java threads and Hibernate DAOs
jQuery in Action, 3rd edition