Reputation: 259
This question is related to PoolingClientConnectionManager (HttpClient 4.2.5 API)
I have max 5 remote connections in the pool and a list of more than 20 url's to download files from. I release the connection after downloading the file. But I don't give any timeout value. What would happen after I have downloaded files from 5 different URL's. I think what I have gathered from the documentation is that the 6th file will not begin downloading till the time the client detects that a connection has been closed from it's end. Is it so? What can I do to close the socket as soon as I have downloaded the file from a URL. Please note that all the URL's from which I am downloading a file from are on different servers.
Upvotes: 2
Views: 3427
Reputation: 27558
Releasing a connection back to the manager does not guarantee its immediate disposal. Most likely the manager will attempt to keep the connection alive. You have two options here (1) as correctly pointed out by user2310289 you might want to implement a custom connection that shuts down connections indiscriminately upon their release or (2 (recommended)) implement a custom eviction policy to evict persistent connections after a certain period of inactivity as described in the HttpClient tutorial
Upvotes: 3
Reputation: 44844
According to The HTTPClient webpage
The correct way is
} finally {
// Release the connection.
method.releaseConnection();
}
The docs also mention that in order to enforce closure of the connection the most simply way is to override the connectionManager, which in your case is the PoolingClientConnectionManager.
If you look at the code at here your can see that you can change the releaseConnection method. Specifically change line 255 so that if the connection is open then shut it down.
Upvotes: 3