Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 43,369,020 milliseconds ago. The last packet sent successfully to the server was 43,369,020 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.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
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:3313)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1940)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2228)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
at com.worldepop.core.business.impl.JPAVirtualTransactionManagerImpl.getAllTransaction(JPAVirtualTransactionManagerImpl.java:86)
at com.worldepop.web.timer.VirtualTransactionTimer.run(VirtualTransactionTimer.java:51)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.net.SocketException: 断开的管道
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3294)
解决办法:
如果连接闲置过长 (长时间内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat.
不用hibernate的话, connection url加参数: autoReconnect=true
用hibernate的话, 加如下属性:
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
要是还用c3p0连接池:
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.validate">true</property>
由于问题产生的根本原因在于服务到数据库的连接长时间没活动,既然重新连接的办法无效,就可以尝试另外一种办法,就是反空闲。
自己写一个线程来反空闲的话,比较麻烦。
最后在网上找到一个办法。为hibernate配置连接池,推荐用c3p0,然后配置c3p0的反空闲设置idle_test_period,只要小于MySQL的wait timeout即可。
在hibernate.cfg.xml中的c3p0链接池的配置中增加下面项:
<!-- configuration pool via c3p0-->
<property name="c3p0.idle_test_period">120</property> <!-- seconds --><!-- default: 0 -->
分享到:
相关推荐
hibernate自动重新连接数据库proxool的使用及配置
dbcp连接池优化详解,主要是如何应对链接僵死的现象
serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false username: root password: 123456 默认用户名和密码为 root / 123456 默认数据库名为:...
maxWait="10000" username="(此处填你的数据库用户名)" password="(此处填你的数据库密码)" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/ccs?autoReconnect=true" /> ...
useUnicode=true&characterEncoding=GB2312&autoReconnect=true jdbc.username.mysql=root jdbc.password.mysql=root 3、 Web容器:tomcat6.x 4、 页面访问路径: 论坛首页: http://localhost:8080/bbs 后台管理...
c3p0 重新自动连接 c3p0 重新自动连接 c3p0 重新自动连接 &autoReconnect=true
autoReconnect=true&characterEncoging=utf8&zeroDateTimeBehavior=convertToNull 3. 完整的配置参数参考intouch2.war!\WEB-INF\config\config.xml 4. 配置文件config.xml中的mail.upflow.com换成实际的...
autoReconnect=true&useUnicode=true&characterEncoding=GB2312</value><br/> </parameter><br/> <parameter><br/> <name>username</name><br/> <value>root</value><br/> </parameter><br/> <parameter><br/> ...
一.开发环境 IDEA + JDK8 + MySQL5.7 + navicate 二.技术栈 Springboot+Mybatis+layui 三....数据库地址url修改为 spring.datasource.url=jdbc:mysql://localhost:3306/score?...autoReconnect=true&use
自动重新连接自动重新连接 。 该脚本适用于非订户。 当您打开新的IRCCloud页面时,此脚本将重新连接到所需的断开连接的网络。 支持的浏览器:带有Firefox和带有Chrome
<Resource driverClassName=...autoReconnect=true" />
autoReconnect=true&useUnicode=true&characterEncoding=utf-8 <property name="username"> <value>empty <property name="password"> <value>empty 在dataSourceConfig.properties中配置数据库...
数据库对象 Java 轻量级库,用于在基于 JDBC 的关系数据库中存储和... autoReconnect=true maxReconnects=3 用法 定义一个实体: @DbEntity(name = "user") public class User { ..... } 定义一个属性: @Db
autoReconnect=true&useUnicode=true&characterEncoding=GB2312</value><br/> </parameter><br/> <parameter><br/> <name>username</name><br/> <value>root</value><br/> </parameter><br/> <parameter><br/> ...
OpenAMEE 平台 在本地运行平台 在 settings.xml 中创建一个 Maven 配置文件 ...autoReconnect=true & autoReconnectForPools=true & useCompression=false < rabbitmq>localhost</ rabbitmq>
修改mysql 8.0版本使用 server.servlet.context...characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8 db.user=root db.password=123456
var autoReconnect = true; var autoMark = true; var slack = new Slack(authToken, autoReconnect, autoMark); slack.on('open', function() { console.log("opened"); }); slack.on('message', function...
#demo中有一个对数据库的简单操作,数据库链接句柄net.pocrd.demo.datasource.url=jdbc:mysql://127.0.0.1:3306/demo?autoReconnect=true&useUnicode=true&characterset=utf-8#数据库用户名...
autoReconnect=true&useSSL=false " export SPRING_DATASOURCE_USERNAME= " springuser " export SPRING_DATASOURCE_PASSWORD= " ThePassword " 要求 Java JDK 可选的: Mysql(仅在需要持久性数据存储时才需要。...
autoReconnect=true <property name="user">root <property name="password">password <property name="initialPoolSize">10 <property name="minPoolSize">10 <property name="maxPoolSize">20 ...