Three timeout settings in httpClient in Java
This article introduces three timeout settings in httpClient in Java.
In the HttpClient package of Apache, there are three timeout settings:
/* Obtain the connection timeout value from the connection pool */ConnManagerParams. setTimeout (params, 1000);/* connection timeout */HttpConnectionParams. setConnectionTimeout (params, 2000);/* request timeout */HttpConnectionParams. setSoTimeout (params, 4000 );
First, ConnectionPoolTimeout:
Defines the timeout time for retrieving connections from the connection pool managed by ConnectionManager.
ConnectionPoolTimeoutException is thrown when an error occurs.
Second, ConnectionTimeout:
Defines the timeout time for establishing a connection with the server through the network. The Httpclient Package creates a socket connection with the server through an asynchronous thread, which is the timeout time for the socket connection.
When an error occurs while connecting to the HTTP server or waiting for a valid connection to be managed by HttpConnectionManager, ConnectionTimeoutException is thrown.
Third, SocketTimeout:
This defines the timeout time for Socket Data Reading, that is, the time needed to wait for the response data to be obtained from the server.
When the read or receive Socket times out, SocketTimeoutException is thrown.