一尘不染

发生MySql错误-“上次发送到服务器的数据包是在0毫秒前”

tomcat

我似乎在一夜之间在我的应用程序中遇到了异常。

我的环境是使用Tomcat的Java
Web应用程序,用Java6编写并在MySQL上运行,并且使用Hibernate3连接到数据库(使用MySQL连接器5.0.3-mysql-
connector-java-5.0.3-bin.jar)

有一个调度的作业会在夜间运行(使用石英作为调度程序),并且在凌晨3点运行时,在尝试访问数据库时会出现以下异常(请注意,我已使用“
xxx”重命名了堆栈跟踪的位)是我工作的公司的内部代码):

03:00:00 ERROR bernate.transaction.JDBCTransaction: JDBC begin failed
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3118)
    at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5215)
    at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
    at org.apache.commons.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 xxx.HibernateSession.beginThreadTransaction(HibernateSession.java:75)
    at xxx.HibernateSession.beginTransaction(HibernateSession.java:141)
    at xxx.TestCaseManager.runAllTestsInBackground(TestCaseManager.java:228)
    at xxx.scheduler.Job.execute(Job.java:42)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)


** END NESTED EXCEPTION **



Last packet sent to the server was 0 ms ago.
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2515)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3118)
    at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5215)
    at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
    at org.apache.commons.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 xxx.HibernateSession.beginThreadTransaction(HibernateSession.java:75)
    at xxx.HibernateSession.beginTransaction(HibernateSession.java:141)
    at xxx.TestCaseManager.runAllTestsInBackground(TestCaseManager.java:228)
    at xxx.scheduler.Job.execute(Job.java:42)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
03:00:00 ERROR bernate.transaction.JDBCTransaction: JDBC begin failed
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

早晨,登录到应用程序(也需要数据库访问)时,它也会出现类似的异常,但是在等待约5分钟并重试之后,我们可以进入该应用程序。

我已经检查了数据库,并且可以对要连接的表执行简单的SELECT。任何帮助,将不胜感激。


阅读 1091

收藏
2020-06-16

共1个答案

一尘不染

您的DBCP连接池正在使用以下配置进行超时…

一种简单的解决方案是使DBCP在将连接提供给调用方之前先对其进行验证。将以下属性添加到BasicDataSource配置中:

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

有关所有选项的列表,请参见此处:http :
//commons.apache.org/dbcp/configuration.html

编辑:对于正在发生的情况稍作修改,请参见下面的MJB评论。

2020-06-16