HttpClient - Best Pratices - Layer4
Except to manage specific resources other than http / https (ftp, gopher, file …), use the HttpClient and not the HttpURLConnection, and avoid to use both at the same time. The HttpClient is more mature and has a richer feature set as multi-threaded management, cookies, pipelining, connection pools …
Instantiation
Instantiating a HttpClient is costly in resources, we must focus on reuse, even singletons, as described in the doc:
« Generally it is recommended to have a single instance of HttpClient per communication component or even per application. However, if the application makes use of HttpClient only very infrequently, and keeping an idle instance of HttpClient in memory is not warranted, it is highly recommended to explicitly shut down the multithreaded connection manager prior to disposing the HttpClient instance. This will ensure proper closure of all HTTP connections in the connection pool. »
Read full article from HttpClient - Best Pratices - Layer4
No comments:
Post a Comment