Monday, August 22, 2011

[android-developers] Re: BitmapFactory.decodeStream() blocking

That's indeed interesting.
In parallel of the code above blocking on decoding a FileInputStream,
I concurrent threads
invoking BitmapFactory.decodeStream() with an InputStream from a
HttpGet executed by a slightlly modified AndroidHttpClient (to use
httpclient/httpcore 4.1).

I'm using a single HttpClient instance for the lifetime of my app, as
recommended by Apache. It is quite
inefficient to create a HttpClient per request as a HttpClient
creates a thread pool and it is designed to
handle several concurrent connections is a thread safe way (if using a
ThreadSafeClientConnManager that is).

Now it really looks like a deadlock in nativeDecodeStream() but if
that's the case it is a bug.

I will try to create a HttpClient per request to see if it fixes the
problem.


On Aug 23, 1:25 am, Rich <aguynamedr...@gmail.com> wrote:
> Hey...I had a similar issue that I just fixed today, and this information
> might help.
>
> I had code I was using all over the place that would be downloading data and
> images with a single HttpClient and everything was fine.  When I moved this
> code over to a project that was downloading a bunch of images in a row,
> sometimes it would hit a point where it would block almost exactly as you're
> describing.  I did a ton of troubleshooting with my HttpClient instance, the
> HttpParams, moving from AsyncTask to a single background thread running in
> serial, etc.
>
> I took a step back and started using a single AndroidHttpClient per-request
> and closing it after I was done downloading the stream and decoding the
> bitmap.  No more blocking.  The issue is that the HttpClient will clean
> itself up, but sometimes not in time and the next request would come in and
> cause a deadlock.
>
> If you're not explicitly cleaning up the HttpClient
> (AndroidHttpClient.close), give it a try.

--
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

No comments:

Post a Comment