________________________________
Da: Oleg Kalnichevski <[email protected]>
A: Alex <[email protected]>
Cc: "[email protected]" <[email protected]>
Inviato: Martedì 18 Dicembre 2012 14:20
Oggetto: Re: PoolingClientConnectionManager set max number of requests
Thanks Oleg, it works like a charm ;) !
Only one thing, I set 2 max connections for my pooledConnetion like this
int maxConnection = 2;
cm = new PoolingClientConnectionManager(schemeRegistry);
cm.setMaxTotal(maxConnection);
cm.setDefaultMaxPerRoute(maxConnection);
HttpHost localhost = new HttpHost(urlServer, port);
cm.setMaxPerRoute(new HttpRoute(localhost), maxConnection);
and I aspect when call in multithread program
DefaultHttpClient ret = new DefaultHttpClient(cm);
that threads take the connection if one of two connection is not used but wait
until one connection is free, but debugging my code all thrad get HttpClient.
Is it possible to have a BlockingPool configuring same parameters or could you
give me some hints to do that ?
Thanks you very much
On Mon, 2012-12-17 at 07:08 +0000, Alex wrote:
> Hi,
>
> I thinking to use PoolingClientConnectionManager to connect to EPP server.
> The costrains for this server are :
> 1) number of max parallel connections
> 2) number of max requests in single connection and after use new connect
>
> For this task PoolingClientConnectionManager :
>
> 1) perfect ! I can set the max number of parallel connection !
> 2) no help or support for this
>
> Can anyone help me or give me any hint to implement the second point ?
>
> Thank you very much
Custom connection re-use strategy and connection metrics are your
friends
---
DefaultHttpClient client = new DefaultHttpClient();
client.setReuseStrategy(new DefaultConnectionReuseStrategy() {
@Override
public boolean keepAlive(HttpResponse response, HttpContext context)
{
boolean result = super.keepAlive(response, context);
if (result) {
HttpConnection conn = (HttpConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
HttpConnectionMetrics metrics = conn.getMetrics();
if (metrics.getRequestCount() > 0) {
return false;
}
}
return result;
}
});
---
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]