Hi,

I forgot to write that if I use url.openConnection() or an other http
library, then this problem doesn't occur, only one connection is used.

On Wed, Dec 11, 2019 at 10:50 AM Tamás Barta <[email protected]> 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()) {
>   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
>

Reply via email to