简体   繁体   English

通讯链接故障问题

[英]Communications link failure issue

I hosted my first Java EE web site but my mySQL connections are timing out after few minutes and I am getting this error message: 我托管了我的第一个Java EE网站,但几分钟后我的mySQL连接超时,并且收到以下错误消息:

HTTP Status 500 - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

type Exception report

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

description The server encountered an internal error that prevented it from fulfilling this request.

exception

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

Last packet sent to the server was 0 ms ago.
dao.OffreDaoImpl.lister(OffreDaoImpl.java:95)
filters.PrechargementFilter.doFilter(PrechargementFilter.java:96)
org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)

root cause

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

Last packet sent to the server was 0 ms ago.
sun.reflect.GeneratedConstructorAccessor28.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:525)
com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985)
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
com.jolbox.bonecp.PreparedStatementHandle.executeQuery(PreparedStatementHandle.java:172)
dao.OffreDaoImpl.lister(OffreDaoImpl.java:90)
filters.PrechargementFilter.doFilter(PrechargementFilter.java:96)
org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)

root cause

java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2431)
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2882)
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
        com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
com.jolbox.bonecp.PreparedStatementHandle.executeQuery(PreparedStatementHandle.java:172)
dao.OffreDaoImpl.lister(OffreDaoImpl.java:90)
filters.PrechargementFilter.doFilter(PrechargementFilter.java:96)
org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108) 

I asked my hoster to increase the timeout value and here is his response: 我要求托管人增加超时值,这是他的回答:

Please accept our sincerest apologizes for misunderstanding. 请接受我们的真诚的歉意。 Unfortunately due to shared hosting environment your request could not be >accomplished - it will affect other customers, that share server resources >for you. 不幸的是,由于共享的托管环境,您的请求无法完成-这将影响其他为您共享服务器资源的客户。 (10 min is max value for this parameter). (此参数的最大值为10分钟)。 Since you strongly need some features - we can only suggest you considering >to move to VPS or dedicated server where you will have full admin >privileges and can do whatever you want without affecting of another >customers. 由于您强烈需要某些功能-我们仅建议您考虑移至VPS或专用服务器,在该服务器上您将拥有完全的管理权限,并且可以做任何您想做的事而不会影响其他客户。

As a solution, we would like to suggest you to add in your jdbc connection >string following command: &autoReconnect=true&failOverReadOnly=false&maxReconnects=10 作为解决方案,我们建议您在以下命令中添加jdbc connection> string:&autoReconnect = true&failOverReadOnly = false&maxReconnects = 10

In this case, after timeout, you will be reconnected again. 在这种情况下,超时后,您将重新连接。

So I edited my config.properties file: 所以我编辑了config.properties文件:

url = jdbc:mysql://localhost:3306/myDatabase&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
driver = com.mysql.jdbc.Driver
username = xxxxxx
password = xxxxxx

But I am still facing the same issue. 但是我仍然面临着同样的问题。

Yes I am using localhost even when I host the website. 是的,即使托管网站,我也使用localhost。 But I tried to replace localhost string by the server address IP in the URL connection and I got this error message: 但是我尝试用URL连接中的服务器地址IP替换localhost字符串,但收到此错误消息:

Caused by: java.sql.SQLException: Unable to open a test connection to the given database. 原因:java.sql.SQLException:无法打开到给定数据库的测试连接。 JDBC url = jdbc:mysql://xxx.xxx.xxx.xx:3306/database_db?autoReconnect=true&failOverReadOnly=false&maxReconnects=10, username = user_name. JDBC网址= jdbc:mysql://xxx.xxx.xxx.xx:3306 / database_db?autoReconnect = true&failOverReadOnly = false&maxReconnects = 10,用户名=用户名。 Terminating connection pool. 终止连接池。 Original Exception: ------ com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. 原始异常:------ com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:无法创建与数据库服务器的连接。 Attempted reconnect 10 times. 尝试重新连接10次。 Giving up. 放弃。

So I noted the issue to my hoster and here is his reply: 因此,我向主持人指出了这个问题,这是他的答复:

Dear Customer, 尊敬的客户,

Kindly use localhost instead IP address, as for your string, we actually asking you to not maintain connections as long as you wish. 请使用本地主机而不是IP地址,因为对于您的字符串,我们实际上要求您不要随意维护连接。 The thing is we have hard limit on opened connections overall = 300 and 50 per user. 问题是,我们对打开的连接有严格的限制,即每个用户300和50。

And as this is shared server these connections are being allocated on demand to each user, and if your account consumes 50 connections it is 1/6 of all connections available. 由于这是共享服务器,因此这些连接将按需分配给每个用户,如果您的帐户消耗了50个连接,则它是所有可用连接的1/6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM