英文:
What is the default timeout for URL in Java? How does this affect url.openStream()?
问题
什么是Java中URL
的默认超时时间?
这如何影响url.openStream()
?
英文:
What is the default timeout for URL
in Java?
How does this affect url.openStream()?
答案1
得分: 1
有两种类型的超时:连接超时
和读取超时
。
连接超时和读取超时的默认值都是-1(无限大)
。
openStream()
建立连接并提供输入流,因此openStream()
会受到连接超时和读取超时的影响。
JDK中的以下代码解释了这一点:
package sun.net;
public class NetworkClient {
/* 如果未指定,默认的读取超时值(无限大) */
public static final int DEFAULT_READ_TIMEOUT = -1;
/* 如果未指定,默认的连接超时值(无限大) */
public static final int DEFAULT_CONNECT_TIMEOUT = -1;
...
}
英文:
There are two types of timeouts: connection timeout
and read timeout
.
Default will be -1 (infinity)
for connection timeout and read timeout.
openStream()
makes connection and provides input stream so openStream()
will have impact from connection timeout and read timeout.
The following code in JDK explains this:
package sun.net
public class NetworkClient {
/* Default value of read timeout, if not specified (infinity) */
public static final int DEFAULT_READ_TIMEOUT = -1;
/* Default value of connect timeout, if not specified (infinity) */
public static final int DEFAULT_CONNECT_TIMEOUT = -1;
...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论