数据库连接超时异常

The last packet successfully received from the server was 32,399,735 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1112)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3092)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3526)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:5022)
at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:63)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:494)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:315)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:257)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:652)
at com.sinosoft.sepmis.inspection.service.InspectionDataServiceImpl$$EnhancerByCGLIB$$e65cc02b.saveInspectionData()
at com.sinosoft.sepmis.util.ConnectionTelnet.execute(ConnectionTelnet.java:319)
at com.sinosoft.sepmis.util.InspectionUtil.inspectExecute(InspectionUtil.java:331)
at com.sinosoft.sepmis.util.InspectionUtil.timer(InspectionUtil.java:79)
at com.sinosoft.sepmis.quartz.QuartzJobTask.execute(QuartzJobTask.java:196)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2539)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2989)
... 23 more
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:

原因:数据库连接超时造成,
解决:
方法1、修改mysql数据库wait_timeout配置属性,将mysql数据库连接时间增长。

方法2、修改Hibernate配置

<!-- lang: xml -->
<prop key="hibernate.connection.autoReconnect">true</prop>
<prop key="hibernate.connection.autoReconnectForPools">true</prop>
<prop key="hibernate.connection.is-connection-validation-required">true</prop>

 

发表评论