Issue
I am new to hibernate and spring. We've a spring based service, which is using oracle database using hibernate. This service is deployed to 4 hosts.
We have one external java client which is using our service. It makes about ~40 service calls per second. So ideally there should be at most 40(calls)*4(hosts)=160 open connections. But for some reason, the DB connections used by our service grow even more than 600.
Can we set up some metrics for checking the leak in DB connections? How can we find out these leak connections?
Any help would be appreciated.
Thanks, Kevin
Solution
If you are using 3rd party jars for connection polling then you can enable their logging and set logAbandoned property to true. So it will log your all logAbandoned connections.
As shown below -
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="${dataSource.driverClassName}" />
<property name="url" value="${dataSource.url}" />
<property name="username" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />
<property name="validationQuery" value="${datasource.validationQuery}" />
<property name="maxActive" value="${datasource.maxActive}" />
<property name="maxIdle" value="${datasource.maxIdle}" />
<property name="maxWait" value="${datasource.maxWait}" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="minIdle" value="${datasource.minIdle}" />
<property name="initialSize" value="${datasource.initialSize}" />
<property name="timeBetweenEvictionRunsMillis" value="${datasource.timeBetweenEvictionRunsMillis}" />
<property name="logAbandoned" value="${datasource.logAbandoned}" />
</bean>
Answered By - Pramod Kumar