【发布时间】:2013-02-18 17:33:04
【问题描述】:
我正在使用 RESTlet ClientResource 从服务器资源调用 Google Places 端点。具体来说,REST 请求调用 RESTlet ServerResource,后者调用 ClientResource 并返回 Google Places 结果。这在 Tomcat 中作为 Web 应用程序运行。
这可以正常工作大约一个小时,然后每个请求都会挂起。停止 tomcat 后,我看到所有请求都在日志中得到处理。这是非常不稳定的,因为 Tomcat 需要每隔一小时重新启动一次。
我已经寻找了一段时间的答案,发现问题可能是连接没有被释放。建议是在表示上使用耗尽并在客户端资源上停止。
我使用的是restlets 2.1.1的最新稳定版。
这是我执行上面解释的过程的方式:
ClientResource storeRoot = new ClientResource(placeEndPoint);
Client c = (Client)storeRoot.getNext();
String jsonString = storeRoot.get().getText();
try {
c.stop();
} catch (Exception e) {
e.printStackTrace();
}
storeRoot.release();
在服务器资源返回表示的部分中,我称之为排气:
JSONArray ja = new JSONArray(placesList);
JsonRepresentation jr = new JsonRepresentation(ja);
jr.setCharacterSet(CharacterSet.UTF_8);
try {
jr.exhaust();
jr.release();
} catch (IOException e) {
e.printStackTrace();
} finally{
}
return jr;
有谁知道如何阻止客户端资源挂起?
【问题讨论】:
标签: tomcat7 restlet freeze restlet-2.0