简体   繁体   English

Java:URLConnection的合理超时期限

[英]Java: Reasonable timeout period for URLConnection

By default the timeout for URLConnection is 0 which is unlimited. 默认情况下,URLConnection的超时为0,这是无限的。 What is a reasonable value for XXXXX? XXXXX的合理值是多少?

URL url = ...
URLConnection uCon = url.openConnection();
uCon.setConnectTimeout(XXXXXX);

It entirely depends on your business logic. 这完全取决于您的业务逻辑。 How long do you want your program to wait before it decides that it will just give up, rather than wait? 您希望程序等待多长时间才能决定放弃,而不是等待?

("Maybe if I just wait a little longer, then it'll connect!") (“也许如果我再等一会儿 ,它将连接!”)

Anything is reasonable. 一切都合理。 Depending on the latency, on the target page. 根据延迟,在目标页面上。 etc. Let's say 30 seconds. 等等。假设30秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM