也许我的怀疑有点傻。但我找不到与我的问题类似的答案。但经过一段时间的请求(大约20次调用此方法)后,客户端获得了java.lang.OutOfMemoryError:Java堆空间
客户是:
final ClientResource cr = new ClientResource(host + userInteracId);
try {
Client httpClient = new Client(Protocol.HTTP);
httpClient.setConnectTimeout(36000);
cr.setNext(httpClient);
JSONObject obj = new JSONObject();
JsonRepresentation jr = new JsonRepresentation(obj);
cr.put(jr);
jr.release();
cr.setNext(httpClient);
Representation r = cr.get();
result = new JsonRepresentation(r).getJsonObject();
r.release();
} catch (Exception e) {
result = new JSONObject();
} finally {
cr.release();
cr.getResponseEntity().release();
}
和例外是:
WARNING: Unexpected error while controlling connector
java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:39)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:312)
at org.restlet.engine.io.Buffer.createByteBuffer(Buffer.java:64)
at org.restlet.engine.io.Buffer.<init>(Buffer.java:125)
at org.restlet.engine.connector.Way.<init>(Way.java:97)
at org.restlet.engine.connector.OutboundWay.<init>(OutboundWay.java:105)
at org.restlet.engine.connector.ClientOutboundWay.<init>(ClientOutboundWay.java:59)
at org.restlet.engine.connector.HttpClientOutboundWay.<init>(HttpClientOutboundWay.java:59)
at org.restlet.engine.connector.HttpClientHelper.createOutboundWay(HttpClientHelper.java:63)
at org.restlet.engine.connector.Connection.<init>(Connection.java:128)
...
答案 0 :(得分:0)
如果在jr.release()或r.release()之前引发异常,那么这些方法将永远不会被调用。 finally块中调用的唯一release()是cr,而不是jr或r。
我建议在catch块中添加一些日志,以查看是否抛出异常。