Java中httpClient中的三种超时设置小结-Java基础-Jsp教程-壹聚教程网www.111cn.net
上面文章有相关介绍;
privatefinalint connectionRequestTimeout; 等待链接池给出一个可用链接超时
privatefinalint connectTimeout; 向server端发起tcp链接超时
即
connect
public void connect(SocketAddress endpoint,
int timeout)
throws IOException
将此套接字连接到服务器,并指定一个超时值。超时值零被解释为无限超时。在建立连接或者发生错误之前,连接一直处于阻塞状态。
参数:endpoint - SocketAddresstimeout - 要使用的超时值(以毫秒为单位)。 抛出:从以下版本开始:1.4
privatefinalint socketTimeout;
即
setSoTimeout
public void setSoTimeout(int timeout)
throws SocketException
启用/禁用带有指定超时值的 SO_TIMEOUT,以毫秒为单位。将此选项设为非零的超时值时,在与此 Socket 关联的 InputStream 上调用 read() 将只阻塞此时间长度。如果超过超时值,将引发 java.net.SocketTimeoutException,虽然 Socket 仍旧有效。选项必须在进入阻塞操作前被启用才能生效。超时值必须是 > 0 的数。超时值为 0 被解释为无穷大超时值。
参数:timeout - 指定的以毫秒为单位的超时值。 抛出:从以下版本开始:JDK 1.1 另请参见:
package org.apache.http.client.config;
import java.net.InetAddress;
import java.util.Collection;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
/*** Immutable class encapsulating request configuration items.* The default setting for stale connection checking changed* to false, and the feature was deprecated starting with version 4.4.*/
@Immutable
public class RequestConfig implements Cloneable {
public static final RequestConfig DEFAULT = new Builder().build();
private final boolean expectContinueEnabled;
private final HttpHost proxy;
private final InetAddress localAddress;
private final boolean staleConnectionCheckEnabled;
private final String cookieSpec;
private final boolean redirectsEnabled;
private final boolean relativeRedirectsAllowed;
private final boolean circularRedirectsAllowed;
private final int maxRedirects;
private final boolean authenticationEnabled;
private final Collection targetPreferredAuthSchemes;
private final Collection proxyPreferredAuthSchemes;
private final int connectionRequestTimeout;
private final int connectTimeout;
private final int socketTimeout;
private final boolean contentCompressionEnabled;