On Wed, 2019-12-11 at 10:50 +0100, Tamás Barta wrote:
> Hi!
> 
> I'm using httpclient-4.5.2.redhat-2.jar and I have a question I hope
> somebody can explain for me.
> I use this simple sample code to connect to a server a few times:
> 
> try (CloseableHttpClient client = HttpClients.custom().build()) {

Why on earth would you want to create a new HttpClient instance for
each and every request?

Oleg


>   for (int i=0; i<20; i++) {
>     try (CloseableHttpResponse response = client.execute(new
> HttpGet("
> https://www.amazon.com";))) {
>       System.out.println("Executed: " + getStatusCode(response));
>     }
>   }
> }
> 
> I use "netstat" to check the outgoing connections. For almost every
> url I
> tried netstat connections only increase by 1 and it is very well.
> 
> But when I use url "https://www.google-analytics.com/collect"; then
> every
> get request creates a new connection and I can see 20 new TIME_WAIT
> rows in
> netstat.
> 
> I tried everything the find out what makes the difference, but I
> can't. I
> wonder how can I achieve that GA connections would be reused too. If
> I turn
> logging on there is no difference in the logs for both urls.
> 
> Thanks, Tamás


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to