2019-03-16 17:43:37 [ERROR]-[Thread: Druid-ConnectionPool-Create-769429195]-[com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run()]: create connection SQLException, url: jdbc:mysql://192.168.1.73:3306/hengjia_ltdb?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true, errorCode 0, state 08S01 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 1,000 milliseconds ago. The last packet sent successfully to the server was 1,000 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3559) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3459) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3900) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) at com.mysql.jdbc.ConnectionImpl.pingInternal(ConnectionImpl.java:3938) at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker.isValidConnection(MySqlValidConnectionChecker.java:107) at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1366) at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1654) at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2570) Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3008) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3469) ... 11 more
上面是报错。
项目运营一段时间会报这个错。
druid版本1.1.14,mysql-connector-java版本5.1.44,连接语句:jdbcUrl = jdbc:mysql://XXXXXXX:3306/XXXX?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true.
在线用户数大概1W+。 一天会报十几次这个错。报错后项目卡顿,查询很慢。都要手动重启项目解决。
网上有提供解决:‘据温少说,升级到 1.1.14 并且配置 keepAlive=true,问题可解决。另如果看报错日志,同时也会提示大家在 URL 中配置:autoReconnect=true’,但是【keepAlive=true】这个不懂在哪里补充上去。
public void onStart() {
DruidDataSource ds = (DruidDataSource)DbKit.getConfig().getDataSource();
ds.setKeepAlive(true);
}