com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

最近在项目上线测试阶段发现了一个问题,查看后台日志的时候经常出现一个WARN的信息,WARN
内容如下:
[WARN ] 2016-04-21 12:58:36,509 method:com.mchange.v2.resourcepool.BasicResourcePool AcquireTask.run(BasicResourcePool.java:1841)com.mchange.v2.resourcepool.BasicResourcePool AcquireTask@5484fa7f – Acquisition Attempt Failed!!!
Clearing pending acquires. While trying to acquire a needed new resource,
we failed to succeed more than the maximum number of allowed acquisition attempts (5). Last acquisition attempt exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:357)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor23.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)atcom.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)atcom.mchange.v2.resourcepool.BasicResourcePool.access 800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool AcquireTask.run(BasicResourcePool.java:1810)atcom.mchange.v2.async.ThreadPoolAsynchronousRunner PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.(Socket.java:434)
at java.net.Socket.(Socket.java:244)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:307)
… 19 more

第一眼看到这个信息以为是c3p0配置出现了错误(最终原因确实是由于数据库配置的某些原因),
因为项目中使用了多个数据源,其中有一个还未上线的模块使用的数据源在项目现场时没有的,只有在
公司的环境才有这数据源(mysql:192.168.10.220),项目环境的ip都是(172.16.6.xx).以
至于项目中的c3p0配置中多了一个错误的环境,最后导致c3p0就会定时去检查数据源,然后抛出了上
面的WARN信息。

你可能感兴趣的:(c3p0)