Best Practice to Use HttpClient in Multithreaded Environment

后端 未结 5 1878
猫巷女王i
猫巷女王i 2020-11-27 09:40

For a while, I have been using HttpClient in a multithreaded environment. For every thread, when it initiates a connection, it will create a completely new HttpClient instan

5条回答
  •  猫巷女王i
    2020-11-27 10:45

    With HttpClient 4.5 you can do this:

    CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).build();
    

    Note that this one implements Closeable (for shutting down of the connection manager).

提交回复
热议问题