/** * 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. * *<p> 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).
* <p>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* </p>
* <p>
* Default: {@code -1}
* </p>
*/
public int getSocketTimeout() {
return socketTimeout;
}
1. connectTimeOut:指建立連接的超時時間,比較容易理解
2. connectionRequestTimeOut:指從連接池獲取到連接的超時時間,如果是非連接池的話,該參數暫時沒有發現有什么用處
3. socketTimeOut:指客戶端和服務進行數據交互的時間,是指兩者之間如果兩個數據包之間的時間大於該時間則認為超時,而不是整個交互的整體時間,比如如果設置1秒超時,如果每隔0.8秒傳輸一次數據,傳輸10次,總共8秒,這樣是不超時的。而如果任意兩個數據包之間的時間超過了1秒,則超時。
線上問題:設置sockettimeout 15秒,但是實際到達156秒,線程數陡增,導致機器崩潰,具體原因有待抓包分析
1.RequestConfig 的配置
2.sockettimeout
