1

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

4

2 回答 2

1

首先,如果一个请求需要 6 秒,那么 1000 万条记录将需要 115 天。因此,在使用一些多线程技术从客户端提高性能之前,您应该首先将响应时间从 6 秒减少到几百毫秒。

于 2012-06-05T04:28:05.370 回答
1

使用此代码 ,这将在调用 REST 时提高性能,因为它使用 Jax api 类,如 WebResource 等......

于 2012-06-06T07:14:30.450 回答