-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Description
WxPayServiceApacheHttpImpl.java这个类中发送http请求时,可以使用连接池的形式吗?这里没有使用连接池是有哪方面的考虑吗?
@Override public String post(String url, String requestStr, boolean useKey) throws WxPayException { try { HttpClientBuilder httpClientBuilder = this.createHttpClientBuilder(useKey); HttpPost httpPost = this.createHttpPost(url, requestStr); try (CloseableHttpClient httpClient = httpClientBuilder.build()) { try (CloseableHttpResponse response = httpClient.execute(httpPost)) { String responseString = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); this.logRequestAndResponse(url, requestStr, responseString); if (this.getConfig().isIfSaveApiData()) { wxApiData.set(new WxPayApiData(url, requestStr, responseString, null)); } return responseString; } } finally { httpPost.releaseConnection(); } } catch (Exception e) { this.logError(url, requestStr, e); if (this.getConfig().isIfSaveApiData()) { wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage())); } throw new WxPayException(e.getMessage(), e); } }