问题描述
Poolthreadstacktraces:Thread[C3P0PooledConnectionPoolManager[identityToken->1brasyf95l92zyz1d2slpg|2bc50502]-HelperThread-#1,5,main]java.net.DualStackPlainSocketImpl.connect0(NativeMethod)java.net.DualStackPlainSocketImpl.socketConnect(UnknownSource)java.net.AbstractPlainSocketImpl.doConnect(UnknownSource)java.net.AbstractPlainSocketImpl.connectToAddress(UnknownSource)java.net.AbstractPlainSocketImpl.connect(UnknownSource)java.net.PlainSocketImpl.connect(UnknownSource)java.net.SocksSocketImpl.connect(UnknownSource)java.net.Socket.connect(UnknownSource)java.net.Socket.connect(UnknownSource)java.net.Socket.<init>(UnknownSource)java.net.Socket.<init>(UnknownSource)com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)sun.reflect.NativeConstructorAccessorImpl.newInstance(UnknownSource)sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnknownSource)java.lang.reflect.Constructor.newInstance(UnknownSource)com.mysql.jdbc.Util.handleNewInstance(Util.java:411)com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)Thread[C3P0PooledConnectionPoolManager[identityToken->1brasyf95l92zyz1d2slpg|2bc50502]-HelperThread-#0,5,main]java.net.DualStackPlainSocketImpl.connect0(NativeMethod)java.net.DualStackPlainSocketImpl.socketConnect(UnknownSource)java.net.AbstractPlainSocketImpl.doConnect(UnknownSource)java.net.AbstractPlainSocketImpl.connectToAddress(UnknownSource)java.net.AbstractPlainSocketImpl.connect(UnknownSource)java.net.PlainSocketImpl.connect(UnknownSource)java.net.SocksSocketImpl.connect(UnknownSource)java.net.Socket.connect(UnknownSource)java.net.Socket.connect(UnknownSource)java.net.Socket.<init>(UnknownSource)java.net.Socket.<init>(UnknownSource)com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)sun.reflect.NativeConstructorAccessorImpl.newInstance(UnknownSource)sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnknownSource)java.lang.reflect.Constructor.newInstance(UnknownSource)com.mysql.jdbc.Util.handleNewInstance(Util.java:411)com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)Thread[C3P0PooledConnectionPoolManager[identityToken->1brasyf95l92zyz1d2slpg|2bc50502]-HelperThread-#2,5,main]java.net.DualStackPlainSocketImpl.connect0(NativeMethod)java.net.DualStackPlainSocketImpl.socketConnect(UnknownSource)java.net.AbstractPlainSocketImpl.doConnect(UnknownSource)java.net.AbstractPlainSocketImpl.connectToAddress(UnknownSource)java.net.AbstractPlainSocketImpl.connect(UnknownSource)java.net.PlainSocketImpl.connect(UnknownSource)java.net.SocksSocketImpl.connect(UnknownSource)java.net.Socket.connect(UnknownSource)java.net.Socket.connect(UnknownSource)java.net.Socket.<init>(UnknownSource)java.net.Socket.<init>(UnknownSource)com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)sun.reflect.NativeConstructorAccessorImpl.newInstance(UnknownSource)sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnknownSource)java.lang.reflect.Constructor.newInstance(UnknownSource)com.mysql.jdbc.Util.handleNewInstance(Util.java:411)com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)2014-10-2621:15:14[com.mchange.v2.async.ThreadPoolAsynchronousRunner]-[DEBUG]Apparentlysomethreadshavebeenreplaced.Replacementthreadprocessingenabled.2014-10-2621:15:15[com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG]Anexceptionoccurredwhileacquiringapoolableresource.Willretry.com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:CommunicationslinkfailureThelastpacketsentsuccessfullytotheserverwas0millisecondsago.Thedriverhasnotreceivedanypacketsfromtheserver.
解决方案
解决方案二:
你的代码呢,贴出来看看
解决方案三:
MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。解决办法有两个:一是修改my.cnf:[mysqld]wait_timeout=31536000interactive_timeout=31536000
解决方案四:
二是在连接URL上添加参数:&autoReconnect=true&failOverReadOnly=false
解决方案五:
继续深入研究一下吧。
解决方案六:
jar包加了吗?
解决方案七:
如果是8小时问题,这么配置:<beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><propertyname="driverClassName"value="com.mysql.jdbc.Driver"></property><propertyname="url"value="jdbc:mysql://...."></property><propertyname="username"value="...."></property><propertyname="password"value="...."></property><propertyname="validationQuery"value="SELECT1"></property><propertyname="testWhileIdle"value="true"></property><propertyname="timeBetweenEvictionRunsMillis"value="3600000"></property><propertyname="minEvictableIdleTimeMillis"value="18000000"></property><propertyname="testOnBorrow"value="true"></property></bean>