java.net.ConnectException:连接超时
我有一个脚本,可以向特定服务器发出数千个 http 请求。该脚本运行了一段时间,然后给我一个连接超时异常。确切的异常如下: org.apache.commons.httpclient.HttpMethodDirector - 处理请求时捕获 I/O 异常 (java.net.ConnectException):连接超时。 我见过很多类似异常的论坛,但没有人谈论 http 调用最初工作然后突然失败。 非常感谢任何帮助。
I have a script that makes several thousands of http requests to a specific server. This script works for some time and then gives me a connection timeout exception. The exact exception is as follows:
org.apache.commons.httpclient.HttpMethodDirector - I/O Exception (java.net.ConnectException) caught when processing request: Connection timed out.
I have seen a lot of forums for similar exception, but no one talks about the http call initially working and then suddenly failing.
Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在短时间内向该服务器发出 1000 个请求,您可能会不知所措,特别是如果您尝试并行发出它们(即线程,即使在单核计算机上,您仍然可以发出大量并行请求)。当连接到任何远程系统时,即使是隔壁房间的系统,您也必须准备好干净地处理各种异常。您可能需要考虑为此设置重试周期以及重试次数的限制。
If you're making 1000s of requests to this server in short order you might be overwhelming it, especially if you're trying to make them in parallel(i.e. threads, even on a single core machine you can still make alot parallel requests). When connecting to ANY remote system, even one in the next room over, you have to be prepared to handle all sorts of exceptions cleanly. You might want to consider a retry cycle for this and a limit on the number of retries.