求助:c3p0不定期出现SQLException: An attempt ...异常

07-08-31 shaohuxie
求助

项目采用spring2.0 + struts 1.3.5 + spring jdbc

Dao层采用spring提供的声明式事务控制

Web服务器为Tomcat 5.0.28

问题现象:

最近该项目在做系统测试,服务运行一段时间之后,c3p0-0.9.0.4出现SQLException: An attempt by a client to checkout a Connection has timed out异常信息

在出现异常的同时,采用其他的客户端连接数据库没有问题。出现该问题之后,重启Tomcat服务器又能稳定运行一段时间。

在google上未找到答案。期待热心人解答

2
shaohuxie
2007-08-31 15:15
详细异常信息

<p class="indent">org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.<p class="indent">Caused by: <p class="indent">java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.<p class="indent">	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)<p class="indent">	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)<p class="indent">	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:262)<p class="indent">	at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)<p class="indent">	at com.mchange.v2.c3p0.ComboPooledDataSource.getConnection(ComboPooledDataSource.java:521)<p class="indent">	at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:200)<p class="indent">	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:350)<p class="indent">	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:262)<p class="indent">	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)<p class="indent">	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)<p class="indent">	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:630)<p class="indent">	at com.ge.gdc.management.dao.GDCHF0005A02Dao$$EnhancerByCGLIB$$2004b336.findMaxTimeAndMinTime(<generated>)<p class="indent">	at com.ge.gdc.management.service.impl.GDCHF0005A02BlogicImpl.findMaxTimeAndMinTime(GDCHF0005A02BlogicImpl.java:224)<p class="indent">	at com.ge.gdc.management.action.GDCHF0005A02Action.find(GDCHF0005A02Action.java:99)<p class="indent">	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<p class="indent">	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<p class="indent">	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<p class="indent">	at java.lang.reflect.Method.invoke(Method.java:324)<p class="indent">	at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)<p class="indent">	at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)<p class="indent">	at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)<p class="indent">	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)<p class="indent">	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)<p class="indent">	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)<p class="indent">	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)<p class="indent">	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)<p class="indent">	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)<p class="indent">	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)<p class="indent">	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157

shaohuxie
2007-08-31 15:16
详细异常信息

Caused by: com.mchange.v2.resourcepool.TimeoutException: internal -- timeout at awaitAcquire()
	at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:970)
	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:260)
	... 53 more

slangmgh
2007-09-05 14:38
不了解c3p0具体是什么。

但是,从异常的字面意义上和stack trace上来看,很可能是connection pool获取的时候出现死锁或者别的问题(原因是获取connection的锁无法获得),导致无法获得连接。

[该贴被slangmgh于2007年09月05日 14:39修改过]

slangmgh
2007-09-05 16:29
另外还有一种可能,就是connection没有归还到缓冲池,如果缓冲池有设最大值,但是交易过程中有connection泄漏,那么一段时间后,就会出现这个问题。

仅供参考。

猜你喜欢
2Go 1 2 下一页