[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-11 Thread ivan
I ended up NOT going with an interrupt, as it seemed to be (as Bob explained) a crap-shoot. Instead when a user wants to stop an I/O - connection operation I orphan the the blocking thread and set it to die on it's next loop. Since most of the resources are released by the non-blocking thread

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-08 Thread Bob Kerns
Well, there's interrupting the IO loop, and there's backing out of the blocked IO system call. GENERALLY SPEAKING, you won't be able to force an ARBITRARY OS to give you back control if it's actually in a blocked IO system call. If you can on a specific OS, and it improves your app in some way

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread DanH
In the general (platform agnostic) case you solve this by having the stream relay though a service of some sort (eg, a thread) that is listening for messages from both the HTTP stream handler and whatever entity you have that will send the interrupt message. How you'd do this best on Android I

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread ivan
Thanks for all the replies! From another thread I've tried: mInputStream.close(); mRequest.abort(); mClientConnectionManager.shutdown(); mDownloadThread.interrupt(); All allow the read operation to complete. Maybe I shouldn't be using a SingleClientConnManager ... ? On Jan 7, 10:25 am, DanH

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread JP
Alternatively, you could lower the connect and read timeout values at the HttpClient level and manage connectivity (that's what I do - I go with 3s connect timeout and retry if it fails). On Jan 7, 9:07 am, ivan istas...@gmail.com wrote: I'm wondering what the currently suggested method is for

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread ivan
Can you change the timeout values once they've been set, or would you have to re-instantiate the HttpClient? On Jan 7, 12:30 pm, JP joachim.pfeif...@gmail.com wrote: Alternatively, you could lower the connect and read timeout values at the HttpClient level and manage connectivity (that's what I

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread Streets Of Boston
In my experience, if you use AsynTasks (or Future? instances) to do your HTTP I/O in the background, calling cancel(true) on these instances will interrupt the HTTP I/O. If i'm not mistaken, the apache HttpClient is sensitive to calling interrupt() on the thread on which it is doing HTTP I/O. On

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread ivan
Were you using SingleClientConnManager or ThreadSafeClientConnManager? I've tried interrupting the thread blocking on the I/O operation, and it doesn't throw an InterruptedException. My guess is because it isn't in a wait(), sleep() or join() call as explained here:

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread Tabman
I think you can extend the InputStream class and override its read method and inside read you can cancel/stop the read loop operation whenever you want to. Here is the source for InputStream.java http://www.docjar.com/html/api/java/io/InputStream.java.html Let me know if this solves your

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread ivan
Tabman, I think that's the best idea yet, but I'm surprised the Apache classes don't offer some mechanism for manually interrupting the I/O blocks. After all, we can set timeouts on all of the I/O operations, which will interrupt the blocks with socket timeout exceptions etc. Thanks. On Jan 7,

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread Streets Of Boston
I was just using HttpClient (DefaultHttpClient from apache) and its 'execute(...)' method called in the background thread of an AsyncTask. It was properly interrupted when the AsyncTask was cancelled. On Jan 7, 3:17 pm, ivan istas...@gmail.com wrote: Were you using SingleClientConnManager or

[android-developers] Re: How to interrupt a blocking I/O operation?

2011-01-07 Thread Bob Kerns
Tabman's answer might possibly be what you're looking for -- but the more general answer I'd give would be: You can't, and you generally don't need to. What are you really trying to do? Most of the times that people think they want to abort waiting IO, that's really not what they need. It's