aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
Author

Question on Java threads and Hibernate DAOs

Andres Delrotti
Ranch Hand

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

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

In an action class method:

...do something...

....do 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:

....do something....

....do 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: 124

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: http://aspose.com/file-tools
 
subject: Question on Java threads and Hibernate DAOs
 
Similar Threads
Run Method vs. Extending Thread
Design single method with different input type and different data type
mutipart/form-data
Forwarding to another action with parameter
how to send parameter from html to jsp??