我在webapp上使用spring with hibernate(hibernate-core-4.3.8.Final和spring 3.2.11.RELEASE).我使用hikaricp(v 2.2.5)作为连接池impl,它检测连接泄漏并打印下面的堆栈跟踪.我使用spring的声明式事务划分,所以我假设管理和清理资源是由spring/hibernate完成的.因此,我认为spring或hibernate是检测到连接泄漏的原因.
基本上,有一个计时器,当它被触发时,调用一个标有@Transactional注释的spring bean.
@Transactional public class InvoiceCycleExporter {
public runExportInvoiceCycleJob(){
//this method when called is **sometimes** leaking a connection ....
} }
Run Code Online (Sandbox Code Playgroud)
能帮我跟踪连接泄漏的来源吗?
我的appcontext.xml配置数据源,连接池,entitymanager如下
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maximumPoolSize" value="${jdbc.maximumPoolSize}"/>
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="leakDetectionThreshold" value="${jdbc.leakDetectionThreshold}"/>
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="shutdown">
<constructor-arg ref="hikariConfig"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="velosPU"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/> //more stuff ....
</bean>
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪如下:
2015-01-13 14:25:00.123 [Hikari Housekeeping Timer (pool …Run Code Online (Sandbox Code Playgroud)