1

In this code i am reading a value from stream. But readline() method is taking more CPU.Can you help me why is this so and give me suggession to minimize CPU usage.

    HttpURLConnection request = (HttpURLConnection) url.openConnection();
    request.setRequestMethod("POST");
    request.setRequestProperty("Content-Length", "0");
    request.setUseCaches(false);

    InputStreamReader in = new InputStreamReader((InputStream) request.getContent());
    BufferedReader buff = new BufferedReader(in);  

    while(line = buff.readLine() != null) {
   System.out.print("hello");
    }
Yogesh
  • 715
  • 1
  • 7
  • 20

2 Answers2

1

You should be attaching the BufferedReader to the input stream of the request, but I find it hard to believe the statement in your title.

user207421
  • 305,947
  • 44
  • 307
  • 483
1

I'm pretty sure the print statement is the reason for the high cpu load. What happens if you remove it?

Buhb
  • 7,088
  • 3
  • 24
  • 38