restlet 分页 HttpClientHelper start/stop
restlet pagination HttpClientHelper start/stop
我从初始 URI GET 请求开始。我将结果连同 link 返回给下一批记录。我循环遍历直到检索到所有记录。似乎性能受到了影响,因为记录器显示 HttpClientHelper 在每次请求后启动和停止。这是可以避免的吗?
Client client = new Client(new Context(), Protocol.HTTP);
ClientResource clientResource;
JsonRepresentation rep;
JSONObject object;
while(nextURI !=null)
{
clientResource = new ClientResource(nextURI);
//excessive HttpClientHelper start/stop triggered at next line
rep = new JsonRepresentation(service.get(MediaType.APPLICATION_JSON));
clientResource.setNext(client);
.
.
.
}
记录器显示以下内容:
May 13, 2015 9:30:52 AM org.restlet.ext.net.HttpClientHelper start
INFO: Starting the HTTP client May 13, 2015 9:30:53 AM
org.restlet.ext.net.HttpClientHelper start
INFO: Starting the HTTP client May 13, 2015 9:30:53 AM
org.restlet.ext.net.HttpClientHelper start
INFO: Starting the HTTP client May 13, 2015 9:30:53 AM
org.restlet.ext.net.HttpClientHelper stop
INFO: Stopping the HTTP client May 13, 2015 9:30:53 AM
org.restlet.ext.net.HttpClientHelper stop
INFO: Stopping the HTTP client
我认为您调用方法 setNext
太晚了。您需要在任何 HTTP 调用之前和创建 ClientResource
实例后立即调用它,以防止在每次调用时启动客户端连接器。
您可以在下面找到示例:
Client client = new Client(new Context(), Protocol.HTTP);
for (int i = 0; i < 5; i++) {
ClientResource clientResource = new ClientResource("http://...");
clientResource.setNext(client);
Representation representation = clientResource.get();
(...)
}
在这种情况下,客户端连接器只启动一次。
希望对你有帮助,
蒂埃里
我从初始 URI GET 请求开始。我将结果连同 link 返回给下一批记录。我循环遍历直到检索到所有记录。似乎性能受到了影响,因为记录器显示 HttpClientHelper 在每次请求后启动和停止。这是可以避免的吗?
Client client = new Client(new Context(), Protocol.HTTP);
ClientResource clientResource;
JsonRepresentation rep;
JSONObject object;
while(nextURI !=null)
{
clientResource = new ClientResource(nextURI);
//excessive HttpClientHelper start/stop triggered at next line
rep = new JsonRepresentation(service.get(MediaType.APPLICATION_JSON));
clientResource.setNext(client);
.
.
.
}
记录器显示以下内容:
May 13, 2015 9:30:52 AM org.restlet.ext.net.HttpClientHelper start
INFO: Starting the HTTP client May 13, 2015 9:30:53 AM org.restlet.ext.net.HttpClientHelper start
INFO: Starting the HTTP client May 13, 2015 9:30:53 AM org.restlet.ext.net.HttpClientHelper start
INFO: Starting the HTTP client May 13, 2015 9:30:53 AM org.restlet.ext.net.HttpClientHelper stop
INFO: Stopping the HTTP client May 13, 2015 9:30:53 AM org.restlet.ext.net.HttpClientHelper stop
INFO: Stopping the HTTP client
我认为您调用方法 setNext
太晚了。您需要在任何 HTTP 调用之前和创建 ClientResource
实例后立即调用它,以防止在每次调用时启动客户端连接器。
您可以在下面找到示例:
Client client = new Client(new Context(), Protocol.HTTP);
for (int i = 0; i < 5; i++) {
ClientResource clientResource = new ClientResource("http://...");
clientResource.setNext(client);
Representation representation = clientResource.get();
(...)
}
在这种情况下,客户端连接器只启动一次。
希望对你有帮助, 蒂埃里