If the server does not close the connection but stops sending data, in.read() will block. Now notice that the code for HttpURLConnection.HttpInputStream.close() will also try to read from the stream to determine if the end of the stream has been reached ( source code) , close() , in turn, is called from disconnect() . And in the end, you blocked your threads.
So you need to change your logic. I assume that you are closing the connection based on some conditions. Therefore, instead of doing this in different threads, check the conditions before reading the next byte in the read stream, and then turn it off.
And by the way, Thread.interrupt() will not help you, since it will only interrupt threads waiting on monitors while your is waiting in IO.
source share