mybatis报Communications link failure
我有定时任务执行数据库查询,每几分钟一次,压根不会超时,看日志最后一个包也是19ms之前发送的,为什么会报数据库链接失败呢?
我的代码里有自己写了一个mybatis的拦截器,使用了pagehelper的5版本,同时使用了threadlocal来进行数据传递(拦截器里用了这个threadlocal),同时写了一个webListener来进行请求之后的销毁处理,这些会影响到我们的连接池关闭吗?感觉应该不会啊
[09:10:03:163] [10.221.231.214] [INFO] [schedu...read-1] [HttpReportJobDaoImpl] - task completed request is : TaskCompletedRequest{context=null, taskId=5010566995, status=FAILED, msg='org.springframework.dao.DataAccessResourceFailureException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error: ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.exceptions.jdbc4.CommunicationsException MESSAGE: Communications link failure Last packet sent to the server was 19 ms ago. STACKTRACE: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 19 ms ago. 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:406) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3134) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1818) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:998) at sun.reflect.GeneratedMethodAccessor138.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114) at com.sun.proxy.$Proxy189.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:108) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy184.query(Unknown Source) at sun.reflect.GeneratedMethodAccessor134.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) at com.jd.jr.jcca.configuration.mybatis.interceptor.MybatisDataPermissionInterceptor.intercept(MybatisDataPermissionInterceptor.java:64) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy184.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) at sun.reflect.GeneratedMethodAccessor141.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) at com.sun.proxy.$Proxy130.selectOne(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at com.sun.proxy.$Proxy167.getByApplyId(Unknown Source) at com.jd.jr.jcca.bankmanager.service.impl.ApplyDetailServiceImpl.saveApplyDetail(ApplyDetailServiceImpl.java:39) at com.jd.jr.jcca.mq.fmq.listener.FirstSubmitSuccessListener.processApplyMessage(FirstSubmitSuccessListener.java:57) at com.jd.jr.jcca.mq.fmq.listener.FirstSubmitSuccessListener.onMessage(FirstSubmitSuccessListener.java:38) at com.jdjr.fmq.client.consumer.TopicConsumer$1.call(TopicConsumer.java:769) at com.jdjr.fmq.client.consumer.TopicConsumer$1.call(TopicConsumer.java:725) at com.jdjr.fmq.client.consumer.ConsumerRetryLoop.execute(ConsumerRetryLoop.java:34) at com.jdjr.fmq.client.consumer.TopicConsumer.dispatchMessages(TopicConsumer.java:725) at com.jdjr.fmq.client.consumer.TopicConsumer$TopicMessageDispatcher.dispatch(TopicConsumer.java:879) at com.jdjr.fmq.client.consumer.GroupConsumer.pull(GroupConsumer.java:343) at com.jdjr.fmq.client.consumer.GroupConsumer$QueueConsumer.run(GroupConsumer.java:571) at java.lang.Thread.run(Thread.java:745) Caused by: java.net.SocketException: Connection timed out at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3119) ... 49 more ** END NESTED EXCEPTION ** ### The error may exist in com/jd/jr/jcca/unicard/dao/mapper/TUnCallbackLogMapper.java (best guess) ### The error may involve com.jd.jr.jcca.unicard.dao.mapper.TUnCallbackLogMapper.queryBatchForJob ### The error occurred while executing a query ### SQL: SELECT * FROM t_un_callback_log t WHERE t.delete_flag = 1 AND t.status IN ('INIT', 'FAIL') AND t.try_num < 5 AND t.next_time between ? and now() ORDER BY id DESC LIMIT ? ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error: ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.exceptions.jdbc4.CommunicationsException MESSAGE: Communications link failure Last packet sent to the server was 19 ms ago. STACKTRACE: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 19 ms ago.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看不到代码,比较难看出什么问题,有几个地方你检查一下:
1、数据源配置,比方说有效时间,或者testOnBorrow这些。
2、你是不是自己管理了connection连接,比方说使用静态变量存储了connection, 在池管理关闭connection之后,第二次又使用了这个connection。
看异常,感觉像第二种多一点