Http超时时间之SocketTimeout
/**
* Sets the read timeout to a specified timeout, in
* milliseconds. A non-zero value specifies the timeout when
* reading from Input stream when a connection is established to a * resource. If the timeout expires before there is data available * for read, a java.net.SocketTimeoutException is raised. A * timeout of zero is interpreted as an infinite timeout. *
*
Some non-standard implementation of this method ignores the * specified timeout. To see the read timeout set, please call * getReadTimeout(). *
* @param timeout an {@code int} that specifies the timeout * value to be used in milliseconds
* @throws IllegalArgumentException if the timeout parameter is negative *
* @see #getReadTimeout() * @see InputStream#read() * @since 1.5 */
public void setReadTimeout(int timeout) { if (timeout < 0) {
throw new IllegalArgumentException(\"timeout can not be negative\"); }
readTimeout = timeout; }
/**
* Defines the socket timeout ({@code SO_TIMEOUT}) in milliseconds, * which is the timeout for waiting for data or, put differently,
* a maximum period inactivity between two consecutive data packets). *
* A timeout value of zero is interpreted as an infinite timeout. * A negative value is interpreted as undefined (system default). *
*
* Default: {@code -1} *
*/
public int getSocketTimeout() { return socketTimeout; }
1. connectTimeOut:指建⽴连接的超时时间,⽐较容易理解
2. connectionRequestTimeOut:指从连接池获取到连接的超时时间,如果是⾮连接池的话,该参数暂时没有发现有什么⽤处3. socketTimeOut:指客户端和服务进⾏数据交互的时间,是指两者之间如果两个数据包之间的时间⼤于该时间则认为超时,⽽不是整个交互的整体时间,⽐如如果设置1秒超时,如果每隔0.8秒传输⼀次数据,传输10次,总共8秒,这样是不超时的。⽽如果任意两个数据包之间的时间超过了1秒,则超时。
线上问题:设置sockettimeout 15秒,但是实际到达156秒,线程数陡增,导致机器崩溃,具体原因有待抓包分析1.RequestConfig 的配置2.sockettimeout