java.net.SocketException: Broken pipe

Love The Way You Lie 2022-08-06 00:24 282阅读 0赞

原因就是Server端的socket被server主动关闭了。
这个现象非常类似于linux C网络编程中出现的SIGPIPE信号。虽然我没有查到准确的资料,但是我大概可以确定java中的Broken pipe异常就是因为检测到了SIGPIPE。

而产生SIGPIPE的一个典型场景就是在client-server架构中,server端主动关闭了socket连接。这时候client端的socket就会接收到一个RST包。如果我们继续对一个已经接收了RST包的socket调用写操作,就会产生SIGPIPE了。

近期用java写的email服务器经常出现 broken pipe 错误。 经查验

有可能是linux的线程机制会产生JVM出错的问题,特别是在连接高峰期间经常出现这样的问题,tomcat在linux下也出现类似情况。
  解决办法是在环境变量中设置: _JAVA_SR_SIGNUM = 12 基本就可以解决。

在WIN环境变量中设置: _JAVA_SR_SIGNUM =12, 若Linux下用 export _JAVA_SR_SIGNUM =12, 基本就可以解决.
  sun的解释:
  --posted by: cooper
  Below is a clipping from Sun on working around JVM crashes under high
  thread counts in the JVM 1.3 for Linux
  On Linux, use a larger signal number for hotspot thread
  suspension/resumption handler. The signal number being used is
  specified by environment variable _JAVA_SR_SIGNUM. Setting it to a
  number larger than SIGSEGV (11) will solve the problem. A good number
  to use is 12, which is SIGUSR2. Using signal 16 to work around the
  problem might have potential problems. So on tcsh, “setenv
  _JAVA_SR_SIGNUM 12” can solve the problem.

发表评论

表情:
评论列表 (有 0 条评论,282人围观)

还没有评论,来说两句吧...

相关阅读