@JFinal 波总,DruidPlugin有一个问题,就是不能做到已经死掉的线程自动处理.由于数据库的超时是设置的8小时,所以系统启动超过一段时间,会出现一系列的报错,原因我也知道,但是使用DruidPlugin的默认设置也根本没有解决到问题.个人认为这个不是由于DruidPlugin的问题,而是Druid 这个阿里数据库插件本来就不成熟.所以我才用的c3p0的数据源.就没出现这个报错.但是出现了另外一个报错.就是上图的那个报错.我没有任何getconnction()类似的代码,全是用的底层自带的代码.使用DruidPlugin的具体报错为 Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 29,324,843 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3589) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3478) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4019) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2310) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2714) at com.alibaba.druid.wall.WallFilter.preparedStatement_executeQuery(WallFilter.java:622) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2711) at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeQuery(FilterEventAdapter.java:465) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeQuery(FilterChainImpl.java:2711) at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.executeQuery(PreparedStatementProxyImpl.java:145) at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:227) at com.jfinal.plugin.activerecord.DbPro.query(DbPro.java:80) ... 31 more Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3039) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3489) ... 46 more.
Connection conn = getConnection() 这样的代码,如果有的话要自行关闭:
conn.close();
此外,建议换上 DruidPlugin 或者 HikariCpPlugin, C3p0Plugin 太老了很久没更新了