Background
I'm using HttpURLConnection on the client side to consume a response in an HTTP streaming (server push) situation. Although the server may close the connection by closing the response, there's also a need for the client to be able to do this.
Problem
The client processes the InputStream in a separate thread, like this:
@Override
public void run() {
try {
for (int b = in.read(); b >= 0; b = in.read()) {
char c = (char) b;
// Do something with the character
// ...
}
}
catch (IOException e) {
}
}
So when I call HttpURLConnection.disconnect() from the thread that initiated the connection (the important piece of information being that it's a different thread from the one processing the input), that call hangs indefinitely. I even left it overnight and it was still hanging. Even calling Thread.interrupt() didn't help.
Suggestions?