Friday, January 7, 2011

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

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
> "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:
>
> http://developer.android.com/reference/java/lang/Thread.html#interrupt()
>
> On Jan 7, 12:57 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote:
>
>
>
> > 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 Jan 7, 12:07 pm, ivan <istas...@gmail.com> wrote:
>
> > > I'm wondering what the currently suggested method is for interrupting
> > > a read operation of a socket input stream?
>
> > > I know that traditionally the read could be interrupted by closing the
> > > socket from another thread and catching an IOException, but I'm not
> > > quite sure how to get at the socket from the apache classes.
>
> > > Maybe I should use some sort of interruptible channel instead ... ?
>
> > > Any links or help is greatly appreciated.
>
> > > My code looks like this -- minus most of the error handling:
>
> > > org.apache.http.impl.client.DefaultHttpClient
> > > org.apache.http.client.methods.HttpGet
> > > org.apache.http.HttpResponse
>
> > > DefaultHttpClient client = new DefaultHttpClient(httpParameters);
>
> > > HttpGet request = new HttpGet(Uri);
>
> > > HttpResponse response = client.execute(request);
>
> > > InputStream entityStream = response.getEntity().getContent();
>
> > > try
> > > {
> > >    bytesRead = entityStream.read(data);}
>
> > > catch (IOException ex)
> > > {
>
> > > }- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate