java.net.SocketException: 管道损坏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3306244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.net.SocketException: Broken pipe
提问by Benni
I get this error or my jsp page every day:
我每天都会收到此错误或我的 jsp 页面:
java.net.SocketException
MESSAGE: Broken pipe
消息:管道破裂
STACKTRACE:
堆栈跟踪:
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2637)
....
After restarting the tomcat service it works fine. (I use hibernate to connect to the mysql database)
重新启动tomcat服务后,它工作正常。(我使用hibernate连接mysql数据库)
回答by Pascal Thivent
I get this error or my JSP page every day (...)
我每天都会收到此错误或我的 JSP 页面 (...)
I'm going to speculate a bit but if this happens every morning (i.e. after a night of inactivity), then it might be related to the fact that MySQL closes idle connections after 8 hours by default (the wait_timeout).
我要推测一下,但如果这种情况每天早上都发生(即在一夜不活动之后),那么它可能与 MySQL 在默认情况下在 8 小时后关闭空闲连接(the wait_timeout)有关。
If this is the case, either:
如果是这种情况,请执行以下任一操作:
configure tomcat to test connections on borrow using a
validationQueryin the datasource configuration:<parameter> <name>validationQuery</name> <value>select 1</value> </parameter>increase MySQL's
wait_timeoutviamy.cnf/my.ini, or by connecting with a command-line SQL client and enteringSET GLOBAL wait_timeout=86400, or some other suitable number of seconds.
使用
validationQuery数据源配置中的a 配置 tomcat 以测试借用连接:<parameter> <name>validationQuery</name> <value>select 1</value> </parameter>增加 MySQL
wait_timeout通过my.cnf/my.ini,或通过连接命令行 SQL 客户端并输入SET GLOBAL wait_timeout=86400,或其他一些合适的秒数。
I'm not aware of all the consequences of the second option and don't really recommend it, at least not without getting more feedback from MySQL experts.
我不知道第二个选项的所有后果,也不真正推荐它,至少在没有从 MySQL 专家那里得到更多反馈的情况下。
回答by Andreas Dolk
Looks like you (partially) loose the connection to your database. MySQL tries to send something but the connection is lost.
看起来您(部分)失去了与数据库的连接。MySQL 尝试发送一些东西,但连接丢失。
Another mysql/tomcat user who reported a similiar problem, was adviced to use a connection pool, like c3p0. The user replied that he wanted to use the Mysql/tomcat connection pooling first as described in mysqls reference manual.
另一个报告类似问题的 mysql/tomcat 用户被建议使用连接池,如c3p0。用户回复说,他想先使用mysqls参考手册中描述的Mysql/tomcat连接池。

