我们开发了一个Red5应用程序,它使用MySQL作为hibernate的数据库。闲置一段时间(8-9小时)后,我们无法连接到数据库并收到以下错误:
2014-04-02 23:08:43,329 [http-0.0.0.0-5080-exec-1] DEBUG o.h.e.jdbc.spi.SqlExceptionHelper - could not extract ResultSet [n/a]
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 30,065,241 milliseconds ago. The last packet sent successfully to the server was 16 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_27]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.6.0_27]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_27]
at java.lang.reflect.Constructor.newInstance(Constructor.java:534) ~[na:1.6.0_27]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3673) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3562) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4113) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2324) ~[mysql-connector-java-5.1.26-bin.jar:na]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56) ~[hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.getResultSet(Loader.java:2040) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:900) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2526) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2512) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.Loader.list(Loader.java:2337) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:356) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1269) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.2.5.Final.jar:4.2.5.Final]
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268) [hibernate-entitymanager-4.2.5.Final.jar:4.2.5.Final]
at org.red5.core.manager.StreamManager.getAllStreamList(StreamManager.java:304) [StreamManager.class:na]
at org.red5.core.manager.StreamManager.removeGhostStreams(StreamManager.java:76) [StreamManager.class:na]
at org.red5.core.manager.StreamManager.getLiveStreams(StreamManager.java:45) [StreamManager.class:na]
at org.red5.core.Application.getLiveStreams(Application.java:176) [Application.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_27]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.6.0_27]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.6.0_27]
at java.lang.reflect.Method.invoke(Method.java:622) ~[na:1.6.0_27]
at org.red5.server.service.ServiceInvoker.invoke(ServiceInvoker.java:196) [red5.jar:na]
at org.red5.server.service.ServiceInvoker.invoke(ServiceInvoker.java:115) [red5.jar:na]
at org.red5.server.net.servlet.AMFGatewayServlet.handleRemotingPacket(AMFGatewayServlet.java:258) [red5.jar:na]
at org.red5.server.net.servlet.AMFGatewayServlet.serviceAMF(AMFGatewayServlet.java:180) [red5.jar:na]
at org.red5.server.net.servlet.AMFGatewayServlet.service(AMFGatewayServlet.java:118) [red5.jar:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) [javaee-api-5.1.2.jar:5.1.2]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina-6.0.36.jar:6.0.36]
at org.red5.logging.LoggerContextFilter.doFilter(LoggerContextFilter.java:77) [red5.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina-6.0.36.jar:6.0.36]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) [catalina-6.0.36.jar:6.0.36]
at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:891) [tomcat-coyote-6.0.36.jar:6.0.36]
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:750) [tomcat-coyote-6.0.36.jar:6.0.36]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2282) [tomcat-coyote-6.0.36.jar:6.0.36]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146) [na:1.6.0_27]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.6.0_27]
at java.lang.Thread.run(Thread.java:701) [na:1.6.0_27]
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:3119) ~[mysql-connector-java-5.1.26-bin.jar:na]
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3573) ~[mysql-connector-java-5.1.26-bin.jar:na]
... 56 common frames omitted
2014-04-02 23:08:43,330 [http-0.0.0.0-5080-exec-1] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 08S01
2014-04-02 23:08:43,330 [http-0.0.0.0-5080-exec-1] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Communications link failure
这是Hibernate配置:
<properties>
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/butterflydb" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.default_schema" value="butterflydb" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="c3p0.acquire_increment" value="1" />
<property name="c3p0.idle_test_period" value="60" />
<!-- seconds -->
<property name="c3p0.max_size" value="100" />
<property name="c3p0.max_statements" value="0" />
<property name="c3p0.min_size" value="10" />
<property name="c3p0.timeout" value="180" />
<!-- seconds -->
<property name="connection.autoReconnect" value="true" />
<property name="connection.autoReconnectForPools" value="true" />
<property name="connection.is-connection-validation-required" value="true" />
<property name="c3p0.preferredTestQuery" value="select 1;" />
<property name="c3p0.testConnectionOnCheckin" value="false" />
<property name="c3p0.testConnectionOnCheckout" value="true" />
</properties>
答案 0 :(得分:1)
您的属性看起来合适,但如果您是,我会为您的URI添加自动连接;使用mysql时,我对这个参数运气真的很好。
jdbc:mysql://localhost/butterflydb?autoReconnect=true