我想了解一些关于HttpAsyncClient的基本概念。如何处理HttpAsyncClient异常
我没有在这里使用连接池,在这里(1)或(2)关闭失败的http请求的正确方法是什么。
这里有什么性能影响,如果我用每个新请求初始化httpclient?
我是否需要在finally块中关闭所有失败请求的连接,不这样做的缺点是什么?
RequestConfig配置= RequestConfig.custom()setConnectTimeout(3 * 1000).setConnectionRequestTimeout(3 * 1000).setSocketTimeout(30 * 1000).build(); CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()。setDefaultRequestConfig(config).build();
httpclient.start();
尝试{
if (targetHost != null && httpget != null)
response = httpclient.execute(HttpHost, HttpGet);
catch (Exception e) {
throw new CustomException("service.unavailable");
} finally {
if (httpget != null){
httpget.releaseConnection(); (1)
httpclient.close();(2)
}
}
谢谢爱德华,如果我在finally块中根本没有关闭httpclient连接,那么会有新的请求创建一个新的线程而不关闭失败的连接?如果没有finally块,我的代码工作正常。 – Sindhu