获取“java.io.IOException:现有连接被远程主机强行关闭”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37787447/
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
Getting "java.io.IOException: An existing connection was forcibly closed by the remote host"
提问by Rajesh Kohir
I am making rest call to IBM Cloud BPM. Some times calls are working fine.But sometimes it is giving following error.
我正在对 IBM Cloud BPM 进行休息。有时调用工作正常。但有时会出现以下错误。
java.io.IOException: An existing connection was forcibly closed by the remote host.
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
Can any one help me on how to solve this issue.
任何人都可以帮助我解决这个问题。
Any help is greatly appreciated.
任何帮助是极大的赞赏。
回答by curd0
Such behavior could be explained if the HTTP Client you use opens persistent connectionsto the server, and the server occasionally terminates them.
如果您使用的 HTTP 客户端打开与服务器的持久连接,并且服务器偶尔会终止它们,则可以解释这种行为。
Normally, the connection to an HTTP server is closed after each response. With HTTP "keep-alive" you keep the underlying TCP connection open until certain criteria are met. What those conditions are depends on the server, which is free to close the connection after an arbitrary timeout or number of requests (just as long as it returns the response to the current request).
通常,每次响应后都会关闭与 HTTP 服务器的连接。使用 HTTP“保持活动”,您可以保持底层 TCP 连接打开,直到满足某些条件。这些条件是什么取决于服务器,它可以在任意超时或请求数量后自由关闭连接(只要它返回对当前请求的响应)。
When the server closes such a connection the client usually reopens it again, and depending on implementation, may throw an exception or print a warning.
当服务器关闭这样的连接时,客户端通常会再次重新打开它,并且根据实现,可能会抛出异常或打印警告。
For example, Vert.xHttpClient(which opens persistent connections by default) also throws...
例如,Vert.x HttpClient(默认打开持久连接)也会抛出...
java.io.IOException: An existing connection was forcibly closed by the remote host
java.io.IOException: An existing connection was forcibly closed by the remote host
...when the server terminates them.
...当服务器终止它们时。