• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Java threads and Hibernate DAOs

 
Andres Delrotti
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic