Monday, August 29, 2011

[android-developers] Using AndroidHttpClient as a singleton.

By looking at the source of AndroidHttpClient, it appears that it can
be reused and uses a ThreadSafeClientConnManager.

I hope to use it as a singleton to get these benefits across multiple
parts of my code.

Creating a new client per request has worked, but it is inefficient. I
estimate a 20% increase in performance for reusing a client, even if I
am still only using one thread for requests.

Does anyone see a problem with this usage?

I would have to use my own implementation since I do support platforms
lower than Froyo.

It emphasizes calling close() when you are done with it. In my case, I
would not ever really be "done" with it until the process closes.

I could also try to make one instance per thread. But I can see some
benefits to allowing more than one thread to make http requests, if
AndroidHttpClient is useful for this.

Nathan

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