报错只出现在更新数据库的操作时,查询不会报错,并且有时候进行新增操作时会重复添加。
15:43:03.306 [http-nio-8080-exec-5] ERROR com.alibaba.druid.pool.DruidDataSource - discard connection
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 74,907 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
问题分析:超过了数据库的等待时间无操作时,连接被回收。
尝试方法一:show variables like '%timeout%'查看wait_timeout的参数为1800秒,想着调大该参数DBA不允许,作罢。最后发现此方法其实是无用的。
尝试方法二:修改druid配置参数,超时等待时间小于1800秒,配置检测连接是否有效,依旧报错。
尝试方法三:jdbcurl参数后添加?autoReconnect=true&failOverReadOnly=false,无效。
最后找到原因,存放该数据库的服务器io太高,将数据库迁移到另一个服务器,解决问题。