HttpClient 4.3.5 ConnectionRequestTimeOut vs ConnectTimeout for HttpConnectionParams.setConnectionTimeout in 4.0.1

I am trying to upgrade the HttpClient Dependency from 4.0.1 to 4.3.5. And was confused by setting the connection timeout in the new lib. For the following code:

HttpClient httpClient = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 300); 

It will be replaced with the following code:

 RequestConfig config = RequestConfig.custom().setConnectTimeout(300).build(); HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); 

However, I'm not sure whether to use setConnectTimeout or setConnectionRequestTimeout , since I am not familiar with HttpClient. It seems to me that I should use setConnectionTimeout based on a java document in the source code. Can someone please confirm? Thanks in advance.

https://svn.apache.org/repos/asf/httpcomponents/httpclient/tags/4.3.3/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java

 /** * Returns the timeout in milliseconds used when requesting a connection * from the connection manager. A timeout value of zero is interpreted * as an infinite timeout. * <p/> * A timeout value of zero is interpreted as an infinite timeout. * A negative value is interpreted as undefined (system default). * <p/> * Default: <code>-1</code> */ public int getConnectionRequestTimeout() { return connectionRequestTimeout; } /** * Determines the timeout in milliseconds until a connection is established. * A timeout value of zero is interpreted as an infinite timeout. * <p/> * A timeout value of zero is interpreted as an infinite timeout. * A negative value is interpreted as undefined (system default). * <p/> * Default: <code>-1</code> */ public int getConnectTimeout() { return connectTimeout; } 
+6
source share
1 answer

In version 4.3 of the Apache Http Client, the configuration was reorganized (again). new way, like the following code:

 RequestConfig requestConfig =RequestConfig.custom() .setConnectTimeout(connectTimeout) .setConnectionRequestTimeout(connectionRequestTimeout) .setSocketTimeout(socketTimeout).build(); 

Connection timeout is a timeout until a connection to the server is established. ConnectionRequestTimeout is used when requesting a connection from the connection manager.

+9
source

Source: https://habr.com/ru/post/980447/


All Articles