Java: How to promptly stop HttpURLConnection.getInputStream?
<p>This is in a simple test program. The main thread starts a number of child threads. I have added to main:
Runtime.getRuntime().addShutdownHook(hookThread);</p>

<p>When ^C is pressed on the JVM process, this hookThread will set a global shutdown flag, and call interrupt() to all the child threads. </p>

<p>I want all the child threads to return then, but interrupt() does nothing to a child thread if it's in HttpURLConnection.getInputStream(). The child thread returns after its timeout (30 seconds), which is too much delay for me.</p>

<p>What's the best way to promptly interrupt a HttpURLConnection.getInputStream() call?</p>

<p>Following the the top of the stack of child thread after interrupt() has been called on it:</p>

<pre><code>"Thread-0" prio=10 tid=0x0000000040b0f800 nid=0x3eab runnable [0x000000004211b000]
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(SocketInputStream.java:129)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
        - locked &lt;0x00000000fd99ac88&gt; (a java.io.BufferedInputStream)
        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)
        - locked &lt;0x00000000fd997670&gt; (a sun.net.www.protocol.http.HttpURLConnection)
...
</code></pre>
