问题
Excepcion:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
...
Caused by: java.net.SocketException: Broken pipe
I have already read a lot of question similar to this one. So, before declaring this question 'unworthy' let me clarify some things
My JDBC link is fully working.
- No problem of authentication
- Sql is up and running
- The
max_connections
, wich is 300, is never reached - The concurrent thread connections are always between 5 and 9
- Im using MySQL 5.0.95 (Yes... I´know,I have no control on the server resources)
- And Mysql-connector-java 5.1.5
- The mysql performance vars have been configured based on Percona Toolkit
My especific questions are:
- Is this error caused by network? because it looks like totally random.
- Is this the propper mysql-connector for the mysql version or could this be the source of all errors?
Thank you
回答1:
A Broken pipe
message means that the other end closed the connection, possibly because of a wrong order of packets received, or because the state between client and server isn't synchronized or something like that. Perhaps there's a firewall between your application and the server that kills persistent connections? Or perhaps there was nothing going on the pipe (connection) for some time, and the server closed it? In any case, if you are using a connection pooling mechanism (you should!), it should be possible to delegate the handling of such situations to it.
Or, if you intend to always use MySQL, you can try to add failOverReadOnly=false&maxReconnects=10&autoReconnect=true
to your connection string. This is specific to the MySQL JDBC driver, so, I'd really advise you to configure your connection pooling mechanism to test the connections before delivering them to your application.
来源:https://stackoverflow.com/questions/37707104/intermittent-jdbc-broken-pipe-and-link-failure