David, Michael, I get the feeling you have entered a closed loop in your discussion. Please let me add an observer's view, in hope to break the loop. I'll adress this mail to David, since it's whom we are trying to help with his problem. I want to point out that I did not dive into the source code for this mail, neither into that of the HTTP client nor that of David's test program. I gathered my "evidence" just from the natural language parts of the correspondence, and from my user-level knowledge of the HTTP client. So, David:
HttpMethod is not meant to close connections. It is meant to use them, and then give them back to the connection manager, which will decide whether to close or reuse them. There are some cases in which the HttpMethod knows that the connection cannot be reused and closes them, but that's not the regular case. >From one of Michaels remarks I learned that you are creating a new instance of the HTTP client and connection manager for each request. Which means you are not using the HTTP client in the way it is meant to be used. This may or may not indicate a deficiency in the documentation. It probably does, see below. Actually, the connections do not leak when you execute your HTTP method, or finish executing it. They leak when you forget about the current connection manager rather than reusing it for the next request. The difference in behavior between Linux and Windows is due to the fact that the Linux JVM has a fall-back cleanup mechanism which closes the connection, while the Windows JVM has not. If you restructure your application, no fall-back cleanup will come into this and behaviour will be similar on both platforms. I guess the sample code on how to use the HTTP client for a single request does not point out which part of the code is a one-time initialization and which part needs to be repeated for each request. So let me tell you: 1. The HTTP Client instance and it's connection manager should be created once, during initialization of the application. Both are meant to be reused for all subsequent requests. 2. Connections will be opened, closed or reused implicitly by the connection manager (see 4). 3. The HttpMethod objects can be created for each request, or recycled if you want to. 4. HttpMethod.releaseConnection() must be invoked after each request. It will make sure that the connection used for that request is given back to the connection manager. I hope this helps, Roland
