0

嗨,我在空闲时间或重新启动 mysql 服务后出现以下错误。

当我重新启动 tomcat 服务器时出现此错误,我正在使用以下技术,即。Java,休眠,Spring MySQL

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 22,333 milliseconds ago.  The last packet sent successfully to the server was 26 milliseconds ago.
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
    com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3589)
    com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3478)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4019)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    org.hibernate.loader.Loader.doQuery(Loader.java:802)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    org.hibernate.loader.Loader.doList(Loader.java:2542)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    org.hibernate.loader.Loader.list(Loader.java:2271)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459)
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365)
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    com.eam.db.category.CategoryManagerDaoImpl$3.doInHibernate(CategoryManagerDaoImpl.java:120)
    org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
    com.eam.db.category.CategoryManagerDaoImpl.getCategoryNames(CategoryManagerDaoImpl.java:115)
    com.eam.bus.category.CategoryManager.getCategoryNames(CategoryManager.java:1591)
    com.eam.web.BaseSimpleFormController.init(BaseSimpleFormController.java:183)
    com.eam.web.invoice.SearchInvoicesController.formBackingObject(SearchInvoicesController.java:190)
    org.springframework.web.servlet.mvc.AbstractFormController.getErrorsForNewForm(AbstractFormController.java:361)
    org.springframework.web.servlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:341)
    org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:281)
    org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
    org.logdigger.servlet.filter.LogDiggerServletFilter.doFilter(Unknown Source)
root cause

java.net.SocketException: Software caused connection abort: recv failed
    java.net.SocketInputStream.socketRead0(Native Method)
    java.net.SocketInputStream.read(SocketInputStream.java:129)
    com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114)
    com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161)
    com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189)
    com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3036)
    com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3489)
    com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3478)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4019)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    org.hibernate.loader.Loader.doQuery(Loader.java:802)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    org.hibernate.loader.Loader.doList(Loader.java:2542)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    org.hibernate.loader.Loader.list(Loader.java:2271)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459)
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365)
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    com.eam.db.category.CategoryManagerDaoImpl$3.doInHibernate(CategoryManagerDaoImpl.java:120)
    org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
    com.eam.db.category.CategoryManagerDaoImpl.getCategoryNames(CategoryManagerDaoImpl.java:115)
    com.eam.bus.category.CategoryManager.getCategoryNames(CategoryManager.java:1591)
    com.eam.web.BaseSimpleFormController.init(BaseSimpleFormController.java:183)
    com.eam.web.invoice.SearchInvoicesController.formBackingObject(SearchInvoicesController.java:190)
    org.springframework.web.servlet.mvc.AbstractFormController.getErrorsForNewForm(AbstractFormController.java:361)
    org.springframework.web.servlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:341)
    org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:281)
    org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
    org.logdigger.servlet.filter.LogDiggerServletFilter.doFilter(Unknown Source)

## MySQL

#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://iowdata.iow.com:3306/LDF_Main?autoReconnect=true
hibernate.connection.username test
hibernate.connection.password test123

###########################
### C3P0 Connection Pool###
###########################

hibernate.c3p0.max_size 2
hibernate.c3p0.min_size 2
hibernate.c3p0.timeout 600
hibernate.c3p0.max_statements 100
hibernate.c3p0.idle_test_period 3000
hibernate.c3p0.acquire_increment 2
hibernate.c3p0.validate false
hibernate.c3p0.autoReconnect=true
4

1 回答 1

0

I have fixed this issue as below,

added new jar file hibernate-c3p0-3.6.0.Final.jar

Updated config 'hibernate.properties' file

#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://cdr.com:3306/CDR_Main
hibernate.connection.username test
hibernate.connection.password test123
hibernate.connection.provider_class org.hibernate.connection.C3P0ConnectionProvider
hibernate.connection.autoReconnect true
hibernate.connection.autoReconnectForPools true

###########################
### C3P0 Connection Pool###
###########################

hibernate.c3p0.max_size 2
hibernate.c3p0.min_size 2
hibernate.c3p0.timeout 1800
hibernate.c3p0.max_statements 100
hibernate.c3p0.idle_test_period 3000
hibernate.c3p0.acquire_increment 2
hibernate.c3p0.validate true
hibernate.c3p0.preferredTestQuery=SELECT 1
hibernate.c3p0.testConnectionOnCheckout=true

after making above changes i am able to fix this issue.

于 2013-11-06T18:13:16.097 回答