异常报错:

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(<generated>) ~[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(<generated>) ~[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(<generated>) ~[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(<generated>) ~[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 omitted
Caused 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.缺少如下配置项:

<property name="validationQuery"><value>SELECT 1</value></property>
<property name="testOnBorrow"><value>true</value></property>
<property name="testOnReturn"><value>true</value></property>

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.完整的数据源配置参考:

<bean id="settleDataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
<property name="driverClassName"><value>${settleDataSource.driverClassName}</value></property>
<property name="url"><value>${settleDataSource.url}</value></property>
<property name="username" ><value>${settleDataSource.username}</value></property>
<property name="password"><value>${settleDataSource.password}</value></property>
<property name="maxIdle" value="20" /><!--最大空闲连接 -->
<property name="minIdle" value="10" /> <!--最小空闲连接 --> <property name="maxActive"><value>200</value></property> <!-- 连接池的最大数据库连接数。设为0表示无限制。 -->
<property name="initialSize"><value>10</value></property> <!-- 初始化连接数量 -->
<property name="maxWait" value="10000"/> <!-- 最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。 -->
<property name="removeAbandoned" value="true"/> <!-- 是否自动回收超时连接-->
<property name="removeAbandonedTimeout" value="600" /><!-- 泄露的连接可以被删除的超时值, 单位秒应设置为应用中查询执行最长的时间,单位为秒 -->
<property name="validationInterval" value="60000"/> <!--检查连接死活的时间间隔(单位:毫妙) 0以下的话不检查。默认是0。 --> <property name="validationQuery"><value>SELECT 1</value></property>
<property name="testOnBorrow"><value>true</value></property>
<property name="testOnReturn"><value>true</value></property>
<property name="testWhileIdle"><value>true</value></property> <!-- 验证失败时,是否将连接从池中丢弃 -->
</bean>

mysql wait_timeout 8小时问题解决,tomcat数据源的配置的更多相关文章

  1. TOMCAT数据源连接配置

    /* *本文档简单介绍系统使用TOMCAT6.0数据源方式连接数据库的配置方法: *1,系统环境:  gdczsam4.0 + Tomcat6.0 + JDK1.5 + SQL Server2008 ...

  2. Tomcat数据源(DataSource)简介

    JDBC2.0提供了javax.sql.DataSource接口,它负责建立与数据库的连接,在应用程序中访问数据库时不必编写连接数据库的代码,可以直接从数据源获得数据库连接 1.数据库和连接池 在Da ...

  3. Tomcat数据源

    Tomcat数据源原理,配置,使用 在程序中,使用数据源是可以提升操作性能的,这种性能 的提升依靠运行的操作原理. 传统的JDBC操作: 1. 加载数据库驱动,通过CLASSPATH配置 2. 通过D ...

  4. 阿里巴巴数据源Druid在tomcat中的配置

    这里只说需要的配置文件,不讲具体的项目,仅作为备忘. pom.xml文件添加 <!-- druid --> <dependency> <groupId>com.al ...

  5. Tomcat数据源的原理,配置及使用(JNDI)

    Tomcat数据源的原理,配置及使用 知识点: 1.数据源的作用及操作原理; 2.Tomcat中数据源的配置; 3.数据源的查找及使用 传统JDBC使用过程存在以下四个步骤: 1.加载驱动程序 2.进 ...

  6. Tomcat数据源总结

    一.数据源的由来   JDBC操作主要由以下几步组成: (1)Class.forName(); (2)Connection con  = DriverManager.getConnection(); ...

  7. 关于nodejs中遇到mysql默认8小时连接断开机制的终极简单解决方案

    由于mysql默认8小时连接无访问,就会断开.为此查了一下资料,有同种比较简单的解决方案: 1. 增加 MySQL 的 wait_timeout 属性的值. 修改 /etc/mysql/my.cnf文 ...

  8. Tomcat 数据源的原理、配置、使用

    1.数据源的作用及操作原理 在程序代码中使用数据源是可以提升操作性能的,这种性能的提升依靠于运行的原理. 传统JDBC操作步骤 1.加载数据库驱动程序,数据库驱动程序通过CLASSPATH配置: 2. ...

  9. MySQL wait_timeout参数修改

    MySQL wait_timeout参数修改问题,可能经常会有DBA遇到过,下面就试验一下并看看会有什么现象. wait_timeout分为global级及session级别,如未进行配置,默认值为2 ...

随机推荐

  1. [转]Vmware(vmdk)虚拟机到hyperv(vhd)虚拟机转换

    Vmware(vmdk)虚拟机到hyperv(vhd)虚拟机转换   1.关闭Vmware所有虚拟机 2.合并Vmware磁盘 通常磁盘都分开储存 "C:\Program Files (x8 ...

  2. 20172302 《Java软件结构与数据结构》第五周学习总结

    2018年学习总结博客总目录:第一周 第二周 第三周 第四周 第五周 教材学习内容总结 查找 查找即在某项目组中寻找某一指定目标元素,或确定该组中并不存在此元素.对其进行查找的项目组称为查找池. 1. ...

  3. Centos7 MongoDB-3.4

    MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的 关系型数据库遵循ACID规则 事务在英文中是transaction,和现实世界中的交易很类 ...

  4. Monte Carlo计算Pi,python实现

    Monte Carlo import random import matplotlib.pyplot as plt import numpy as np 6 # 函数模拟点的随机掉落,并分为两组 de ...

  5. Zookeeper学习笔记——2 Shell和Java API的使用

    ZooKeeper的使用一般都接触不到,因为平时工作甚少直接使用ZK.但是通过手动操作一下ZK,还是能对其中的门道了解各一二. shell 常用命令 help 查看所有支持的命令 [zk: local ...

  6. AngularJS中使用$http对MongoLab数据表进行增删改查

    本篇体验使用AngularJS中的$http对MongoLab数据表进行增删改查. 主页面: <button ng-click="loadCourse()">Load ...

  7. Dll注入经典方法完整版

    总结一下基本的注入过程,分注入和卸载 注入Dll: 1,OpenProcess获得要注入进程的句柄 2,VirtualAllocEx在远程进程中开辟出一段内存,长度为strlen(dllname)+1 ...

  8. Android定位&地图&导航——基于百度地图,实现自定义图标绘制并点击时弹出泡泡

    一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二. ...

  9. python 进程池pool简单使用

    平常会经常用到多进程,可以用进程池pool来进行自动控制进程,下面介绍一下pool的简单使用. 需要主动是,在Windows上要想使用进程模块,就必须把有关进程的代码写if __name__ == ‘ ...

  10. MySQL查看数据库表容量大小

    本文介绍MySQL查看数据库表容量大小的命令语句,提供完整查询语句及实例,方便大家学习使用. 1.查看所有数据库容量大小 select table_schema as '数据库', sum(table ...