简体   繁体   中英

Java: Reasonable timeout period for URLConnection

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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