默认超时是多少?对 Java 中的 url.openStream() 有什么影响?

huangapple go评论102阅读模式
英文:

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;
    ...
}

huangapple
  • 本文由 发表于 2020年9月16日 20:17:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63919910.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定