连接池exception GetConnectionTimeoutException get/close not same thread

环境

hibernate 4.2.0.Final

spring 3.2.0.RELEASE

druid 1.0.2

异常信息

Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection

Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 20

[WARN] 09-24 14:11:29 [pool.DruidDataSource.recycle:1132] get/close not same thread

现象分析,20个连接都用完后,就拿不到新连接,查不出数据了

网上查了下

http://www.oschina.net/question/1170760_127675  这里面的描述最像

kalo回复 @千纸鹤 : 是因为我用了Tomcat7,并且Spring里面使用了异步机制。造成了durid连接池打开关闭不是同一线程。 去掉spring对异步的支持,就不会出现这个问题。你可以在Tomcat6里面试试。 具体为什么 异步会造成durid连接池打开关闭不是同一线程,我也不清楚,还在研究。

这个和tomcat无关,tomcat6一样会出现。

解决方法

在spring的sessionFactory的配置中 <property name="hibernateProperties"> 加上

<prop key="hibernate.connection.release_mode">AFTER_TRANSACTION</prop>

问题就解决了。

猜你喜欢

转载自renxiangzyq.iteye.com/blog/2245816