Can disconnect() be safely called from another thread to cancel an ongoing HttpURLConnection?
<p>If I have a <code>java.net.HttpURLConnection</code> that's receiving data (or is about to receive data) in a worker thread, is it safe to call <code>disconnect()</code> to stop it at any point of the connection's lifecycle in another thread?</p>

<p>I'm wondering about this because I couldn't find a clearly documented way to abort an ongoing HTTP connection. Interrupting the worker thread by calling <code>Thread.interrupt()</code> won't work because the <code>InputStream</code> you get from <code>HttpURLConnection</code> is not interruptible.</p>

<p>I did some experiments that look like this:</p>

<pre><code>// MyRequest.run() gets an HttpURLConnection by calling someUrl.openConnection()
MyRequest request = new MyRequest(someUrl);

FutureTask&lt;SomeResult&gt; task = new FutureTask&lt;SomeResult&gt;(request);
someExecutor.execute(task);

// The connection opens, data comes in, ...

// Get the HttpURLConnection from the request, call disconnect()
// Should be part of the cancel() of a FutureTask subclass
request.getConnection().disconnect();    
</code></pre>

<p>It seems to work, and both the connection and the socket object it creates will be eventually cleaned up by gc. Still, I wonder if that's the right way to do it? Will there be any issue with calling <code>disconnect()</code> from another thread?</p>
