I have a web application which has the back end code below....
In an action class method:
MyCustomClass mcc = new MyCustomClass(); <--- in which this class implements runnable
mcc.setInputParameters(param1,param2, datasource) <----- datasource that was set in hibernate config file
** 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:
MyCustomClass mcc = new MyCustomClass();
mcc.setInputParameters(param1,param2) <----- datasource removed as input parameter
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**
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.
subject: Question on Java threads and Hibernate DAOs