Java: Reasonable timeout period for URLConnection

巧了我就是萌 提交于 2019-12-12 21:19:28

问题


By default the timeout for URLConnection is 0 which is unlimited. What is a reasonable value for XXXXX?

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

回答1:


Anything is reasonable. Depending on the latency, on the target page. etc. Let's say 30 seconds.




回答2:


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!")



来源:https://stackoverflow.com/questions/3972345/java-reasonable-timeout-period-for-urlconnection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!