Reputation: 1092
I start off with an initial URI GET request. I get back result along with a link to the next batch of records. I loop thru this until I retrieve all the records. It just seems performance is taking a hit as the logger shows the HttpClientHelper start and stopping after each request. Is this avoidable?
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);
.
.
.
}
Logger shows the following:
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
Upvotes: 2
Views: 341
Reputation: 202146
I think that you call the method setNext
too late. You need to call it before any HTTP call and right after having created your instance of ClientResource
to prevent from the client connector to be started at each call.
You can find a sample below:
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();
(...)
}
In this case, the client connector is only started once.
Hope it helps you, Thierry
Upvotes: 1