javaapache-httpclient-4.xapache-httpasyncclient

PoolingNHttpClientConnectionManager: what is timeToLive attribute for?


I am trying to understand how does timeToLive attribute work?

Is this when you get a connection out of the pool, the time interval after which the connection is deliberately closed and returned to the pool?

API

I want my client that was using persistent connections to close every few seconds, so the requests to load-balancer are going to new server every few seconds.


Solution

  • TTL parameter limits the total time to live of a persistent connection to a finite value. Regardless of keep-alive value returned by the server or client side keep-alive strategy a connection will never be re-used beyond its TTL.

    One of the purpose of the TTL parameter is ensure a more equal redistribution of persistent connection across a cluster of nodes.