java client是什么_java-Apache HttpClient API中CloseableHttpClient和HttpClient有什么区别?

有同样的问题。 其他答案似乎没有解决为什么close()确实是必要的? 而且,Op似乎在努力寻找与HttpClient等一起使用的首选方式。

根据Apache的说法:

// The underlying HTTP connection is still held by the response object

// to allow the response content to be streamed directly from the network socket.

// In order to ensure correct deallocation of system resources

// the user MUST call CloseableHttpResponse#close() from a finally clause.

另外,关系如下:

client.close()(接口)

实施者:

client.close()-线程安全

client.close()-不推荐使用ThreadSafe BUT,请改用client。

client.close()-不是ThreadSafe,但会创建ThreadSafe client。

用于创建CUSTOM client.close()。

client.close()-不是ThreadSafe,但会创建ThreadSafe client。

用于创建默认或最小client.close()。

根据Apache的首选方式:

CloseableHttpClient httpclient = HttpClients.createDefault();

他们给出的示例在client子句中执行client.close(),并且还利用了CloseableHttpClient。

另外,mkyong的执行方式也很有趣:

HttpClient client = HttpClientBuilder.create().build();

他没有显示client.close()电话,但我认为这是必要的,因为client仍然是CloseableHttpClient的一个实例。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值