HttpClient InputStream general advice?
Daniel Fuchs
daniel.fuchs at oracle.com
Mon Nov 2 13:07:46 UTC 2020
Hi Joshua,
On 31/10/2020 00:15, Joshua Anderson wrote:
> Is this checking and reviewing necessary? Should I have written a
> background task that reviews all InputStream’s created by the HttpClient
> and calls .close() if the user forgets. The intent here is to free up
> these resources. Without tracking and reviewing the InputsStream objects
> created by the HttpClient, If the user forgets to call .close() on the
> InputStream objects they request, it eventually affects the stability of
> the core library due to the fact it cannot get new Http connections to
> perform other work. What’s your take?
>
With the current implementation, an application should drain or close
the InputStream if it wants to avoid leaks.
This is clearly stated in the API documentation:
https://docs.oracle.com/en/java/javase/15/docs/api/java.net.http/java/net/http/HttpResponse.BodySubscribers.html#ofInputStream()
Hope this helps,
-- daniel
More information about the net-dev
mailing list