Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the setConnectionTimeout , setSoTimeout and "http.connection-manager.timeout" in apache HttpClient API

What is the difference between the three(marked as comments) :

MultiThreadedHttpConnectionManager connManag =  new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams managParams = connManag.getParams();  managParams.setConnectionTimeout(connectiontimeout); // 1 managParams.setSoTimeout(sotimeout); //2  HttpMethodBase baseMethod = null;  try {   HttpClient client = new HttpClient(connManag);   client.getParams().setParameter("http.connection-manager.timeout", poolTimeout); //3    baseMethod = new GetMethod(…);   int statusCode = client.executeMethod(…);    … } catch (ConnectTimeoutException cte ){   //Took too long to connect to remote host } catch (SocketTimeoutException ste){   //Remote host didn’t respond in time } catch (Exception se){   //Some other error occurred } finally {   if (baseMethod != null)     baseMethod.releaseConnection(); } 

1. setConnectionTimeout - if it determines the timeout until connection is established.

2. setSoTimeout - if it determines the period of inactivity or time difference between two consecutive packets ,

Then what does the below one do :

3. "http.connection-manager.timeout"

like image 216
Prateek Avatar asked Aug 12 '13 10:08

Prateek


People also ask

What is the difference between connection timeout and connection request timeout?

request timeout — a time period required to process an HTTP call: from sending a request to receiving a response. connection timeout — a time period in which a client should establish a connection with a server.

What is connection timeout in HttpClient?

timeout) – the time waiting for data – after establishing the connection; maximum time of inactivity between two data packets. the Connection Manager Timeout (http. connection-manager. timeout) – the time to wait for a connection from the connection manager/pool.

What is HTTP read timeout?

The read timeout is the timeout on waiting to read data1. If the server (or network) fails to deliver any data <timeout> seconds after the client makes a socket read call, a read timeout error will be raised.

What is closeable HttpClient?

CloseableHttpClient is the base class of the httpclient library, the one all implementations use. Other subclasses are for the most part deprecated. The HttpClient is an interface for this class and other classes. You should then use the CloseableHttpClient in your code, and create it using the HttpClientBuilder .


2 Answers

At the lowest level HTTP is TCP socket. So when you request a URL and get a response, at lower level, a client Socket is created which establishes connection to the remote Server Socket, sends some data and receives response.

  • setConnectionTimeout : Client tries to connect to the server. This denotes the time elapsed before the connection established or Server responded to connection request.

  • setSoTimeout : After establishing the connection, the client socket waits for response after sending the request. This is the elapsed time since the client has sent request to the server before server responds. Please note that this is not same as HTTP Error 408 which the server sends to the client. In other words its maximum period inactivity between two consecutive data packets arriving at client side after connection is established.

  • http.connection-manager.timeout : MultiThreadedHttpConnectionManager uses a pool of HTTP connections. It has maximum and minimum values per host set for it. If all the connections for particular host are has reached max value, the request for new connection for the same host will have to wait till any one of the existing connection becomes free. This parameter denotes the time elapsed when a connection request was made and before the HttpConnectionManager returned a connection.

like image 177
Santosh Avatar answered Sep 18 '22 20:09

Santosh


This sequence diagram might help.

apache http api

like image 35
Maria Ines Parnisari Avatar answered Sep 17 '22 20:09

Maria Ines Parnisari