Reputation: 39481
I am doing a HTTPRest post call to send the data to a third party, my data is in the order of 3 to 10 million and i can send only one record per request along with username and password for authentication as specified by third party
sample code that i am using is
public static void main(String[] args) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"http://localhost:8080/RESTfulExample/json/product/post");
StringEntity input = new StringEntity("{\"qty\":100,\"name\":\"iPad 4\"}");
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
if (response.getStatusLine().getStatusCode() != 201) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
for each request it is taking around 6 sec and if i calculate for 10 million records it will take hours , can some one please suggest me are the any ways to improve the performance ??
thanks in advance Sunny
Upvotes: 1
Views: 116
Reputation: 4870
Use This code this will increase performance while calling REST because this uses classs of Jax api like WebResource and so on....
Upvotes: 1
Reputation: 839
First, if one request takes 6 seconds, 10 million records will take 115 days. So you should reduce the response time from 6 seconds to several hundred of milliseconds first before you use some multithread tech to increase performance from cilent side.
Upvotes: 1