博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql wait_timeout 8小时问题解决,tomcat数据源的配置
阅读量:6968 次
发布时间:2019-06-27

本文共 15673 字,大约阅读时间需要 52 分钟。

异常报错:

2017-02-13 09:30:17.597 [startQuertz_Worker-6] ERROR com.autoyol.task.TransStatManageTask#execute [line:257] - 定时任务6. 出错org.springframework.dao.RecoverableDataAccessException: ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 44,997,436 milliseconds ago.  The last packet sent successfully to the server was 44,997,437 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.### The error may exist in com/autoyol/mapper/trans/TransMapper.xml### The error may involve defaultParameterMap### The error occurred while setting parameters### SQL: ~### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 44,997,436 milliseconds ago.  The last packet sent successfully to the server was 44,997,437 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; SQL []; The last packet successfully received from the server was 44,997,436 milliseconds ago.  The last packet sent successfully to the server was 44,997,437 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 44,997,436 milliseconds ago.  The last packet sent successfully to the server was 44,997,437 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98) ~[spring-jdbc-4.0.9.RELEASE.jar:4.0.9.RELEASE]    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.0.9.RELEASE.jar:4.0.9.RELEASE]    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.0.9.RELEASE.jar:4.0.9.RELEASE]    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74) ~[mybatis-spring-1.2.3.jar:1.2.3]    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) ~[mybatis-spring-1.2.3.jar:1.2.3]    at com.sun.proxy.$Proxy34.selectList(Unknown Source) ~[na:na]    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205) ~[mybatis-spring-1.2.3.jar:1.2.3]    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122) ~[mybatis-3.3.0.jar:3.3.0]    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64) ~[mybatis-3.3.0.jar:3.3.0]    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[mybatis-3.3.0.jar:3.3.0]    at com.sun.proxy.$Proxy43.queryAfterXhStartTransRenterInfoList(Unknown Source) ~[na:na]    at com.autoyol.service.trans.TransService.queryAfterXhStartTransRenterInfoList(TransService.java:3859) ~[auto-service-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]    at com.autoyol.service.trans.TransService$$FastClassBySpringCGLIB$$82326640.invoke(
) ~[spring-core-4.0.9.RELEASE.jar:1.0-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) ~[spring-tx-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) ~[spring-tx-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at com.autoyol.service.trans.TransService$$EnhancerBySpringCGLIB$$d1bda840.queryAfterXhStartTransRenterInfoList(
) ~[spring-core-4.0.9.RELEASE.jar:1.0-SNAPSHOT] at com.autoyol.service.trans.TransTaskService.transNotify(TransTaskService.java:983) ~[auto-service-1.0-SNAPSHOT.jar:1.0-SNAPSHOT] at com.autoyol.service.trans.TransTaskService$$FastClassBySpringCGLIB$$13fabb7b.invoke(
) ~[spring-core-4.0.9.RELEASE.jar:1.0-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) ~[spring-tx-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) ~[spring-tx-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644) ~[spring-aop-4.0.9.RELEASE.jar:4.0.9.RELEASE] at com.autoyol.service.trans.TransTaskService$$EnhancerBySpringCGLIB$$d89a1841.transNotify(
) ~[spring-core-4.0.9.RELEASE.jar:1.0-SNAPSHOT] at com.autoyol.task.TransStatManageTask.execute(TransStatManageTask.java:255) ~[auto-service-1.0-SNAPSHOT.jar:1.0-SNAPSHOT] at sun.reflect.GeneratedMethodAccessor3972.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269) [spring-core-4.0.9.RELEASE.jar:4.0.9.RELEASE] at com.autoyol.quartz.BeanInvokingJobDetailFactoryBean$BeanInvokingJob.execute(BeanInvokingJobDetailFactoryBean.java:486) [BeanInvokingJobDetailFactoryBean$BeanInvokingJob.class:na] at org.quartz.core.JobRunShell.run(JobRunShell.java:223) [quartz-1.8.6.jar:na] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) [quartz-1.8.6.jar:na]Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 44,997,436 milliseconds ago. The last packet sent successfully to the server was 44,997,437 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. at sun.reflect.GeneratedConstructorAccessor471.newInstance(Unknown Source) ~[na:na] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_101] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_101] at com.mysql.jdbc.Util.handleNewInstance(Util.java:389) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3609) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2417) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.MultiHostMySQLConnection.execSQL(MultiHostMySQLConnection.java:140) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1203) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at sun.reflect.GeneratedMethodAccessor129.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] at com.mysql.jdbc.MultiHostConnectionProxy$JdbcInterfaceProxy.invoke(MultiHostConnectionProxy.java:91) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] at com.sun.proxy.$Proxy39.execute(Unknown Source) ~[na:na] at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:62) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120) ~[mybatis-3.3.0.jar:3.3.0] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113) ~[mybatis-3.3.0.jar:3.3.0] at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386) ~[mybatis-spring-1.2.3.jar:1.2.3] ... 40 common frames omittedCaused by: java.net.SocketException: Connection timed out at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_101] at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) ~[na:1.8.0_101] at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.8.0_101] at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[na:1.8.0_101] at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) ~[na:1.8.0_101] at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3591) ~[mysql-connector-java-5.1.35-bin.jar:5.1.35] ... 64 common frames omitted

2.mysql数据库的配置

# 28800   8小时# 21600   6小时 SET GLOBAL wait_timeout=21600;SHOW GLOBAL VARIABLES LIKE 'wait_timeout';

3.缺少如下配置项:

SELECT 1
true
true

I had used the same settings in pure JDBC projects few times before and never encoutered similar exception so now I wanted to ask uncle Google for some answers  At the beginning I dove into the MySQL manual to check why autoReconnect isn’t enough in my application but found nothing relevant to my problem. After some thinking I got the idea that maybe some settings in Commons-DBCP are missing so I read dbcp configuration to find that connection could be validated before real usage by specifing two parameters: testOnBorrow=“true” validationQuery=“select 1” . As written in docs:

testOnBorrow – The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. NOTE – for a true value to have any effect, the validationQuery parameter must be set to a non-null string.

validationQuery – The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row.

Link:http://tomaszdziurko.com/2010/06/solving-com-mysql-jdbc-exceptions-jdbc4-communicationsexception-in-spring-jdbc-based-application

4.完整的数据源配置参考:

${settleDataSource.driverClassName}
${settleDataSource.url}
${settleDataSource.username}
${settleDataSource.password}
200
10
SELECT 1
true
true
true

 

转载地址:http://uvisl.baihongyu.com/

你可能感兴趣的文章
OSChina 周一乱弹 ——爱丽三个小时没吃鱼罐头了
查看>>
OSChina 周六乱弹 ——程序员还是大学生的时候 带啥去上学
查看>>
nginx在linux环境下安装
查看>>
14_02_Linux系统启动流程详解之二 内核及init
查看>>
Android Material风格的应用(一)--AppBar TabLayout
查看>>
EasyUI的渣性能
查看>>
puppet自动化运维之cron资源
查看>>
Linux系统下MongoDB的简单安装与基本操作
查看>>
XEN虚拟机复制
查看>>
redis未授权访问导致的安全问题
查看>>
salt Syndic 的实现
查看>>
JSP/Java 获取路径问题
查看>>
我的友情链接
查看>>
43、源码安装MariaDB
查看>>
使用VisualVM、JMC远程监控JVM
查看>>
菜鸟如何应对服务器被黑
查看>>
Java Map接口
查看>>
利用awk i=!i 来输出奇偶行详解
查看>>
iframe高度自适应的方法
查看>>
对素数的判断和素数个数的判断
查看>>