Java BufferedReader readline blocking?

Posted by tgguy on Stack Overflow See other posts from Stack Overflow or by tgguy
Published on 2010-05-05T20:58:05Z Indexed on 2010/05/05 21:28 UTC
Read the original article Hit count: 401

Filed under:
|
|

I want to make an HTTP request and then get the response as sketched here:

URLConnection c = new URL("http://foo.com").openConnection();
c.setDoOutput(true);

/* write an http request here using a new OutputStreamWriter(c.getOutputStream) */

BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream));
reader.readLine();

But my question is, if the request I send takes a long time before a response is received, what happens in the call reader.readLine() above? Will this process stay running/runnable on the CPU or will it get taken off the CPU and be notified to wake up and run again when there is IO to be read?

If it stays on the CPU, what can be done to make it get off and be notified later?

© Stack Overflow or respective owner

Related posts about java

Related posts about io