Three timeout settings in httpClient in Java

This article will introduce you to a summary of the three timeout settings in httpClient in Java.
 
In Apache's HttpClient package, there are three places to set timeout:

/* 从连接池中取连接的超时时间*/ 
ConnManagerParams.setTimeout(params, 1000); 
/*连接超时*/ 
HttpConnectionParams.setConnectionTimeout(params, 2000); 
/*请求超时*/
HttpConnectionParams.setSoTimeout(params, 4000);


First, ConnectionPoolTimeout:
defines the timeout period for taking connections from the connection pool managed by ConnectionManager.
An error will throw a ConnectionPoolTimeoutException


. Second, ConnectionTimeout:  
defines the timeout period for establishing a connection with the server through the network. In the Httpclient package, an asynchronous thread is used to create a socket connection with the server, which is the timeout period for the socket connection.
When connecting to the HTTP server or waiting for a valid connection managed by HttpConnectionManager, a ConnectionTimeoutException will be thrown


. Third, SocketTimeout:    
This defines the timeout time for Socket to read data, that is, the time to wait to obtain response data from the server.
SocketTimeoutException will be thrown when reading or receiving Socket times out

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324174451&siteId=291194637