How to use ThreadSafeClientConnManager.requestConnection (HttpRoute route, object state)

With ThreadSafeClientConnManager.requestConnection (HttpRoute route, object state), what is the second state element that should be?

I end up trying to use ThreadSafeClientConnManager.releaseConnection (ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) to free the connection. But I need a ManagedClientConnection, accessible only from the requestConnection method (via the returned ClientConnectionRequest)

+3
source share
2 answers

It looks like you should be able to safely pass the null value for the status parameter.

DefaultRequestDirector requestConnection ...

Object userToken = context.getAttribute(ClientContext.USER_TOKEN);

// Allocate connection if needed
if (managedConn == null) {
    ClientConnectionRequest connRequest = connManager.requestConnection(route, userToken);

, ( client.execute(httpRequest)), , USER_TOKEN, requestConnection .

+2

, (. ). releaseConnection() , entity.consumeContent() . BasicHttpContext httpclient.execute.

:

this.context = new BasicHttpContext();

httpclient.execute(httppost,context);
String entityStr = EntityUtils.toString(response.getEntity());
response.getEntity().consumeContent();

http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http/examples/client/ClientMultiThreadedExecution.java

- , "" requestConnection: ThreadSafeClientConnManager.requestConnection(HttpRoute route, Object state)

+1

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


All Articles