Memory leaks Jersey客户端连接关闭内存泄漏问题
我正在使用Jersey v10,并编写了以下代码。这是关闭Jersey客户端连接以避免内存泄漏的正确方法吗?在此之前,我没有进行任何调用Memory leaks Jersey客户端连接关闭内存泄漏问题,memory-leaks,connection,client,jersey,resource-leak,Memory Leaks,Connection,Client,Jersey,Resource Leak,我正在使用Jersey v10,并编写了以下代码。这是关闭Jersey客户端连接以避免内存泄漏的正确方法吗?在此之前,我没有进行任何调用 ClientConfig config = setupHttps(); final Client c = Client.create(config); final WebResource r = c.resource(baseUri); ClientResponse response = null; try {
ClientConfig config = setupHttps();
final Client c = Client.create(config);
final WebResource r = c.resource(baseUri);
ClientResponse response = null;
try {
response = r.path("/....")
.header("contentId", id)
.header("sid", sid).get(ClientResponse.class);
...
} catch (Exception e) {
log.error("Error returning contentServiceName.");
} finally {
if (response != null) {
response.close();
}
if (c!= null) {
c.destroy();
}
}
蒂亚,
Vijay据我所知,是的,这是关闭泽西岛客户的正确方式。。。有以下警告 1) 您试图防止的不是内存泄漏,而是(到您正在寻址的服务器的)连接泄漏 2) 以下是关于中的类的内容: 客户端实例是昂贵的资源。建议在创建Web资源时重用已配置的实例。Web资源的创建、请求的构建和响应的接收都是线程安全的。因此,客户端实例和WebResource实例可以在多个线程之间共享 因此,如果你打算打多个电话,最好不要每次都打电话。WebResources也是如此(但程度较小) 3) 我所描述的是Jersey 1.1(但我明白了)